Thursday, 14 March 2013

Calling code behind function from a html button

HTML button click call code behind in asp.net



<input type="button" id="btnuplod" runat="server" value="Upload" onclick="__doPostBack('btnSubmit','Submit');">

Code Behind
 
protected void Page_Load(object sender, EventArgs e)
{
   if (IsPostBack)
   {
      if (Convert.ToString(Request.Form["__EVENTARGUMENT"]) == "Submit")
      {
          btnuplod_Click();//submit action here
      }
   }
}

Your Function


Public void btnuplod_Click()
{
      if (FileUploadPDF.HasFile)
        {
            string fileName = Server.HtmlEncode(FileUpload1.FileName);
            string extension = System.IO.Path.GetExtension(fileName);
            if (extension == ".pdf")
            {

            }
            else
            {
                lblerror.InnerText = "Please upload PDF Files Only";
            }
        }
}
 

No comments:

Post a Comment