First, we will create a project. Then,
Step 1
  1. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  2. <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#,
  1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3. Response.Redirect("HTMLPage1.htm?username=" + TextBox1.Text);
  4. //Passing the value to .htm page using QueryString
  5. }
Step 3: Then, we create a .htm page in our project, like HTMLPage1.htm
In this page, we take an HTML control.
  1. <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
  1. <script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
  2. <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
  3. <script>
  4. $(document).ready(function() {
  5. $("#txtInput").val(getParameterByName("username"));
  6. function getParameterByName(name) {
  7. name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  8. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  9. results = regex.exec(location.search);
  10. return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  11. }
  12. });
  13. </script>

Comments

Join the conversation! Your thoughts help the community grow.