Ajax Postback issue
-
Hi, I am using asp.net 2.0, trying to create chat application. I am copying the user entered text to a asp.net textbox using the following java script function
document.getElementById("TextBox1").value= "chat message entered by user"; userid = location.search.substring( 1, location.search.length ); url = 'Chat.aspx?action=chatmsg&u=' + userid ; req = getAjax(); req.onreadystatechange = function(){ if( req.readyState == 4 && req.status == 200 ) { updateAll(); } } req.open( 'GET', url, true ); req.send( null );
with the following asp.net textbox definition
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack =false ReadOnly=false ></asp:TextBox>
and i am handling the ajax postback @ chat.aspx like this chat.aspx's page load method
protected void Page_Load(object sender, System.EventArgs e)
{
string chatMsg = TextBox1.Text;
}But the problem is i always see the TextBox1.Text as empty instead of "chat message entered by user" which i copied thru javascript function, but i can able to see in internet explorer that the TextBox1.Text gets updated when i call postback. I put alert before calling chat.aspx like this
alert("TextBox1 text VALUE = "+document.getElementById("TextBox1").value);
it is also showing the updated value, but i could not able to see in the codebehind (page_load method) But if i do any postback thru button click, i can able to see the updated vlaue of TextBox1.Text Can somebody help me out.. what went wrong on this? Thanks Srini
-
Hi, I am using asp.net 2.0, trying to create chat application. I am copying the user entered text to a asp.net textbox using the following java script function
document.getElementById("TextBox1").value= "chat message entered by user"; userid = location.search.substring( 1, location.search.length ); url = 'Chat.aspx?action=chatmsg&u=' + userid ; req = getAjax(); req.onreadystatechange = function(){ if( req.readyState == 4 && req.status == 200 ) { updateAll(); } } req.open( 'GET', url, true ); req.send( null );
with the following asp.net textbox definition
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack =false ReadOnly=false ></asp:TextBox>
and i am handling the ajax postback @ chat.aspx like this chat.aspx's page load method
protected void Page_Load(object sender, System.EventArgs e)
{
string chatMsg = TextBox1.Text;
}But the problem is i always see the TextBox1.Text as empty instead of "chat message entered by user" which i copied thru javascript function, but i can able to see in internet explorer that the TextBox1.Text gets updated when i call postback. I put alert before calling chat.aspx like this
alert("TextBox1 text VALUE = "+document.getElementById("TextBox1").value);
it is also showing the updated value, but i could not able to see in the codebehind (page_load method) But if i do any postback thru button click, i can able to see the updated vlaue of TextBox1.Text Can somebody help me out.. what went wrong on this? Thanks Srini
If you run your app and then watch the html source via your browser you will find the ThextBox1 control has some additions. Put that one in your getElementByID().