Thursday 20 March 2014

get html input controls values server side in asp.net

Input value is the html control to get it value into server side we need to make it server side control, and to make any html control to server side control you need to defined server tag as runat=”server” as like below code.
@Defined Input control as server control to read control server side


<input id="inpValue" type="text"  runat="server" />


@C# code to get input control server side
   string value = inpValue.Value;
Some time it happen that you have to create the input control dynamically and this time you read the value is little tough but no warries.


@HTML Code to display button and input control
<form id="form1" runat="server">
    <div>
     <input id="inpValue" type="text"   name="inpValue" />
     <asp:Button ID="btnShow" runat="server" Text="Submit" onclick="btnShow_Click" />
    </div>
    </form>


@C# code to display;
protected void btnShow_Click(object sender, EventArgs e)
        {
            string strValue = Page.Request.Form["inpValue"].ToString();
            Response.Write(strValue);
        }

No comments:

Post a Comment