How to get readonly textbox value in codebehind

Solution

Type following code in aspx design page

<asp:TextBox ID=”TextBox1″ runat=”server” Text=”Hello”></asp:TextBox><br />

<asp:Button ID=”Button1″ runat=”server” Text=”Button” onclick=”Button1_Click” />

 

Type following code in code behind

protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add(“readonly”, “readonly”);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(TextBox1.Text);
}

 

 

 

About the Author

avatar