Cant get text from textbox in method for AjaxFileUpload1_UploadComplete

爱⌒轻易说出口 提交于 2019-12-23 05:14:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21752542/cant-get-text-from-textbox-in-method-for-ajaxfileupload1-uploadcomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!