无法从AjaxFileUpload1

编程入门 行业动态 更新时间:2024-10-25 08:18:23
无法从AjaxFileUpload1_UploadComplete方法的文本框中获取文本(Cant get text from textbox in method for AjaxFileUpload1_UploadComplete)

不知道什么是错的,但是我从ajaxToolKit获得了一个AjaxFileUpload,并且在代码后面的方法中用于上传完成我尝试从我的文本框中获取用户ID以将文档链接到上传的文件。 不知何故,这似乎没有用,什么错?

这是我的aspx

<div class="floatLeft"> <asp:Label id="idSearchLabel" runat="server" >Employee ID:</asp:Label><br /> <asp:TextBox id="idSearchTextBox" runat="server" CssClass="textbox125" ></asp:TextBox> <asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" ControlToValidate="idSearchTextBox" ErrorMessage="Can only be digits." Display="Dynamic" ForeColor="red" ValidationExpression="^[\d]{1,10}" /> </div>

这是我的aspx.cs

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string filePath = "~/Docs/"; try { //get id to attach document to string id = idSearchTextBox.Text; if (!String.IsNullOrEmpty(id)) { //create directory filePath = filePath + id + "/"; Directory.CreateDirectory(Server.MapPath(filePath)); //save file filePath = "~/Docs/" + e.FileName; AjaxFileUpload1.SaveAs(Server.MapPath(filePath)); } else { } } catch { } }

这里涉及上下文吗? 我是如此突然出现。

Don't really know what's wrong but i have an AjaxFileUpload from the ajaxToolKit and in the method in code behind for upload complete i try to fetch the user id from my textbox to link the document to the file uploaded. Somehow, this doesnt seem to work, whats wrong?

Here is my aspx

<div class="floatLeft"> <asp:Label id="idSearchLabel" runat="server" >Employee ID:</asp:Label><br /> <asp:TextBox id="idSearchTextBox" runat="server" CssClass="textbox125" ></asp:TextBox> <asp:RegularExpressionValidator id="RegularExpressionValidator2" runat="server" ControlToValidate="idSearchTextBox" ErrorMessage="Can only be digits." Display="Dynamic" ForeColor="red" ValidationExpression="^[\d]{1,10}" /> </div>

Here is my aspx.cs

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string filePath = "~/Docs/"; try { //get id to attach document to string id = idSearchTextBox.Text; if (!String.IsNullOrEmpty(id)) { //create directory filePath = filePath + id + "/"; Directory.CreateDirectory(Server.MapPath(filePath)); //save file filePath = "~/Docs/" + e.FileName; AjaxFileUpload1.SaveAs(Server.MapPath(filePath)); } else { } } catch { } }

Is there something about context involved here? Im so out in the blue.

最满意答案

问题解决了,我将文本框中的值放入会话中,因为我可以从UpLoadComplete到达会话变量,所有内容都像魅力一样。

Problem solved, I put the value from textbox into session and since I can reach the session variables from the UpLoadComplete everything works like a charm.

更多推荐

id,AjaxFileUpload,filePath,idSearchTextBox,电脑培训,计算机培训,IT培训"/> <me

本文发布于:2023-07-28 23:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!