Fill asp.net textbox with javascript variable.

Last post 04-24-2007 3:26 PM by SuperGhost. 1 replies.

Sort Posts:

  • Fill asp.net textbox with javascript variable.

    04-24-2007, 10:01 AM
    • Loading...
    • folkertsj
    • Joined on 01-16-2006, 5:55 AM
    • Watertown, SD 57201
    • Posts 303

    I am sure this is possible but I am at my wits end with trying to figure this out.  Is there a way to populate an asp.net textbox from a javascript variable.  What I have is a list of time that I am using as a link in a gridview.  When I click on the gridview link, I am having it show a hidden div layer and from there passing a variable TeeTime to it.  My problem is I can use a simple html text box and it show correctly in there but is there a way to make it show up in a server side text box.  <asp:textbox runat="server"......

    <script language="JavaScript1.1">
    <!--
    var TempTeeTime;
    
    function ShowHide0(TeeTime){
        if(document.getElementById("div0").style.display=="block")
    	    document.getElementById("div0").style.display="none";
        else
    	    document.getElementById("div0").style.display="block";	
    	    TempTeeTime = escape(TeeTime)
    	    document.getElementById("testtextbox").value = TempTeeTime;
    	    
        }
    //-->
    </script>
    ASP.NET CODE
    <div id="div0" class="HiddenDiv">
            <table cellpadding="2" style="width: 100%">
                <tr>
                    <td colspan="5">
                        <h4><asp:textbox runat="server" id="txtShowTeeTime"/></h4>
                    </td>
                </tr>
            </table>
    </div>
     Any Help would be appreciated.  Thanks.
  • Re: Fill asp.net textbox with javascript variable.

    04-24-2007, 3:26 PM
    Answer
    • Loading...
    • SuperGhost
    • Joined on 12-29-2005, 11:58 AM
    • Palmdale CA, USA
    • Posts 404

    ASP.NET Server Controls get their ID re-written when the page is rendered. You have to use the ClientID attribute of the control to gain access to it from client-side.

    So try the following:

    document.getElementById("<%=txtShowTeeTime.ClientID%>").value = TempTeeTime;

    ** Hope this helps!

    DennyDotNet.com
    Filed under: ,
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter