Can't read value from textbox into javascript variable

Hello I am trying to read a textbox(runatserver) after is gets populated form the server into a javascript variable,but it gives me a console error that "can't read form NULL" however the text box is populated by the string I want to read

this is my text box:

 <form runat="server">

        <asp:TextBox ID="ServerSideTextBox" runat="server" />
    </form>

This is how I am populating it in C#:

ServerSideTextBox.Text= Object_JSON_Class.JSON_DataTable(dt);

it gets the right data also shows the right data string but the PROBLEM is when I try to read the value of the text box like this:

 var oServerSideTextBox= document.getElementById("ServerSideTextBox"); 
var oServerJSON_String=eval("("+oServerSideTextBox.value+")"); 

I get a console error that I can't read form NULL,but the text box does have the string I want to read into javascript variable,please help

Answers


 var txtToIncr = document.getElementById('<%=ServerSideTextBox.ClientID%>')

Check out this link, about reading ASP.Net controls through javascript


Try this:

var oServerSideTextBox= document.getElementById("<%=ServerSideTextBox.ClientID%>");

If that does not work, try something like this:

var oServerSideTextBox= document.getElementById("<%=ServerSideTextBox.ClientID%>_text");

Components are assigned different ID's when rendered by the client's browser. You can take a look here for more information.


Need Your Help

Adobe Flex 3 : Fault Event doesnt return XML Feed sent from Server

ruby-on-rails flex flex3

I am working on a flex application which communicates with a Rails backened.

Datepicker not showing when clicked the first time

android datepickerdialog

I have a editfield and when I click on it a datepicker will open but I am not able to get the datepicker to popup when clicked for first time. If I click the editfield the first time, the datepicker