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:
In short,
How to prepare Request at HTML
The following code snippet will guide you to prepare sample request.
- <script src="//code.jquery.com/jquery-1.10.2.js">
- </script>
- <script type="text/javascript">
- function sendData()
- {
- var firstName = document.getElementById("Text1").value;
- var lastName = document.getElementById("Text1").value;
- var address = document.getElementById("Text1").value;
- $.post("Services.aspx",
- {
- FirstName: firstName, LastName: lastName, Address: address
- },
- function (data, status)
- {
- alert(data); alert(status);
- });
- }
- </script>
The above script will be used to post data and below one is to get data,
- function getData()
- {
- $.get("Services.aspx",
- function(data, status)
- {
- alert("incoming Data" + data);
- });
- }
General declaration to call,
- <inputid="btnsend" type="button" value="Send" onclick="sendData();" />
- <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:
- protected void Page_Load(object sender, EventArgs e)
- {
- try
- {
- stringFirstName = Request.Form["FirstName"];
- stringLastName = Request.Form["LastName"];
- string Address = Request.Form["Address"];
- string response = "Data Received" + "Last Name is " + FirstName;
- Response.Write(response);
- } catch (Exception ex)
- {
- Response.Write("Error in Request");
- }
- }
Test the scenario,
Home.htmlPassed 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.