Monday 11 June 2012

How to post form data from HTML to ASP.Net page

For sending form data from HTML page to ASP.Net page ,


In HTML page , do the method type as POST and action should be full path of .aspx page.Like
Test.html page
<html>
<body>
 <form id="form1" action="../MailerTest.aspx" method="post"> 

     <input type="text" name="txtName" id="Name" />
    <br/>
    <input type="text" name="txtEmail" id="Email" />
    <br/>
  <input type="submit" name="btnPost" value="Submit" id="btnPost" />
</form>
</body>
</html> 


Default.aspx page
On aspx page , get html controls data on page_load event as
strName = Request.Form["txtName"].ToString();
strEmail = Request.Form["txtEmail"].ToString();


Thing which we need to take care of that Key value in Request.Form should be name
in <input> tag besides of id.After clicking on 'Submit' button HTML page will post data to
aspx page.

No comments:

Post a Comment