質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top