Sunday, August 25, 2013

Calling server side function on fileupload text change in asp.net






How to Post a page to server on fieupload path change by client in asp.net.
Here is a code for doing postback when u click on browse button of a file upload and choose a file then
Page posted to the server through linkbutton refrence and server involk the linkbutton_click event and you can
upload your file at linkbutton click event.


//****************Code of .Aspx File**************
<asp:FileUpload ID="fu" onChange="FileUploadPostBack();"
runat="server" />
<asp:LinkButton ID="lblAddMore" runat="server" OnClick="lblAddMore_Click"> </asp:LinkButton>

//****************Code of CS File**************
  protected void Page_Load(object sender, EventArgs e)
    {
        string jscript = "function FileUploadPostBack(){" + ClientScript.GetPostBackEventReference(lblAddMore.UniqueID, "") + "};";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Key", jscript, true);
    }
    protected void lblAddMore_Click(object sender, EventArgs e)
    {
        if (fu.HasFile)
        {
            //Upload your file here.
        }
    }

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More