Data Communication Between Basic HTML Pages To ASP.NET Web Pages

Introduction

In this article we will see how to pass data over html to aspx. From the principles of programming every web essential programming must contain HTML pages and browsers can run only html sources.

Conceptual view

In this article I will try to show Communication between HTML5 to ASP, o that you can pass data between different programming languages to ASP.NET:

data

In short,

html

How to prepare Request at HTML

The following code snippet will guide you to prepare sample request.

  1. <script src="//code.jquery.com/jquery-1.10.2.js">  
  2.     </script>  
  3.     <script type="text/javascript">  
  4.         function sendData()   
  5. {  
  6.   var firstName = document.getElementById("Text1").value;  
  7.   var lastName = document.getElementById("Text1").value;  
  8.   var address = document.getElementById("Text1").value;   
  9.   $.post("Services.aspx",  
  10.   {  
  11.     FirstName: firstName, LastName: lastName, Address: address  
  12.   },   
  13.          function (data, status)   
  14.   {   
  15.     alert(data); alert(status);  
  16.   });  
  17. }  
  18.    </script>  
The above script will be used to post data and below one is to get data,
  1. function getData()   
  2. {  
  3.     $.get("Services.aspx",  
  4.         function(data, status)   
  5.           {  
  6.             alert("incoming Data" + data);  
  7.         });  
  8. }  
General declaration to call,
  1. <inputid="btnsend" type="button" value="Send" onclick="sendData();" />  
  2. <inputid="btnget" type="button" value="GET" onclick="getData();" />  
Now, let’s come into aspx.cs side to get incoming request. The following snippet is used to get request data in C#.NET:
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.     try  
  4.     {  
  5.         stringFirstName = Request.Form["FirstName"];  
  6.         stringLastName = Request.Form["LastName"];  
  7.         string Address = Request.Form["Address"];  
  8.         string response = "Data Received" + "Last Name is " + FirstName;  
  9.         Response.Write(response);  
  10.     } catch (Exception ex)  
  11.     {  
  12.         Response.Write("Error in Request");  
  13.     }  
  14. }  
Test the scenario,

scenario

Home.html

Passed a request and we can get it into Services.aspx. By this way we can pass data from HTML to ASP.NET sources.

Implementation

We can implement this technique to pass data from (TOMCAT, Web Logic, and PHP) anywhere HTML to ASP.NET. 

Up Next
    Ebook Download
    View all
    Learn
    View all