I want to assign value to text box through Java Script and then access textbox value in C# code.
Here is my code:
JS:
<script>
function myFunction() {
var chk = document.getElementById('<%= CheckBox1.ClientID %>');
if (chk.checked) {
document.getElementById('<%= TextBox1.ClientID %>').disabled = true;
document.getElementById('<%= TextBox1.ClientID %>').value = "BREAK";
}
else {
document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
document.getElementById('<%= TextBox1.ClientID %>').value = "";
}
}
</script>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('"+TextBox1.Text+"')</script>");
}
ASP:
<asp:CheckBox ID="CheckBox1" runat="server" onchange="myFunction();"/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />