Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Ajax Postback issue

Ajax Postback issue

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavajavascriptasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    engsrini
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • E engsrini

      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

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      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().

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups