setting value on ClinetClick and reading changed value on OnClik[Server Side]
-
Hi all, I have a
TextBox and Button
. The Button have two events'OnClentClick'(javascript)
and'OnClick'(server side).
OnClientClick
of button i could able to set the value to textbox and i could see the value in TextBox. But whenOnClick
of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance. -
Hi all, I have a
TextBox and Button
. The Button have two events'OnClentClick'(javascript)
and'OnClick'(server side).
OnClientClick
of button i could able to set the value to textbox and i could see the value in TextBox. But whenOnClick
of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance.Can you please show us the code ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Can you please show us the code ?
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Here is the sample code.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView Export</title>
<script type="text/javascript" language="javascript">
function ChangeText()
{
var tBox = document.getElementById("TextBox1");
tBox.value = "New Text";
alert(tBox.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="Old Text"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="javascript:ChangeText();" />
</div>
</form>
</body>
</html>the code behid page: Firm1.aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
Response.write("New Text"+TextBox1.Text); //out put: "Old Text"[Given at design time]
}please suggest me where i did wrong.
-
Hi all, I have a
TextBox and Button
. The Button have two events'OnClentClick'(javascript)
and'OnClick'(server side).
OnClientClick
of button i could able to set the value to textbox and i could see the value in TextBox. But whenOnClick
of Button i could not able to read the changed value of TextBox. Its giving value which i assigned at design time. But i could see the new value in textbox. Why? whats the reason. How to read that changed value on OnClick(Server Side]. Please suggest me how to do that. Thanks in advance.Beacuse field value set by javascript it not available in server side code but you can access value by classical asp pattern string txtvalue = request.form("fieldname")