First, we will create a project. Then,
Step 1
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <asp:Button ID="Button1" runat="server" Text="Passing value to HTML" onclick="Button1_Click" />
This code will take on the .aspx page.
Step 2: After that we write the code on CodeBehind which is in C#,
- protected void Button1_Click(object sender, EventArgs e)
- {
- Response.Redirect("HTMLPage1.htm?username=" + TextBox1.Text);
-
- }
Step 3: Then, we create a .htm page in our project, like HTMLPage1.htm
In this page, we take an HTML control.
- <input id="txtInput" type="text" />
Step 4 : And last, we write the code in jQuery for fetching the value from URL, like
http://localhost:53563/HTMLPage1.htm?username=Csharp
- <script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
- <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
- <script>
- $(document).ready(function() {
- $("#txtInput").val(getParameterByName("username"));
-
- function getParameterByName(name) {
- name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
- results = regex.exec(location.search);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- }
- });
- </script>