Asp.net access html control textbox element value at code behind

Asp.net access html control textbox element value at code behind

Asp.net how to access html control value. You can access the value of html element in asp.net web application code behind. The important thing to remember is the controls can be accessed at server side using it’s name property and not by ID of it. At client side you can access control by ID or name.

<input id="Text1" name="Text1" type="text" />

In code behind we will access the value of Text control Text1 by it’s name. Below snippet contains html textbox element and asp.net button control.

<body>
    <form id="form1" runat="server">
        <div>
            <p>
                <input id="Text1" name="Text1" type="text" />
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
            </p>
        </div>
    </form>
</body>

On button click event page does post back and we retrieve the value stored in text control.

protected void Button1_Click1(object sender, EventArgs e)
 {
   string inputValue = Request.Form["Text1"];
   
   Response.Write(inputValue);
 }

Request.Form can be used to access all controls on html page.

Note: Don’t forget to add name property value for html control.

Tags:

How To Access Div, Iframe Html Controls Using code behindJQuery Set Value of Textbox or Label Control In Asp.netAsp.net Create Html ControlsGridview select emailJQuery access label control and set valuehtml without using tables tableless html table less html css tableless layoutsAsp.net How to display HTML contentsJquery Dropdown Selected ValueHTML5 Slider control and JavaScriptASP.net monitor server JQuery Get .next() Element

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.