javascript not recognizing textobject

kaisersoze

Centurion
Joined
Aug 27, 2003
Messages
152
hi,
I have a asp:textbox object in the page. I am loading a value into the textbox from server-side. When user clicks on a link, javascript should pick the value from the text box and should show an alert depending on the if stmt.
I know i should do something lke this:

var v = document.getElementById("txtPath").value;

I get error of i do like that (object cannot be null something of that sort)
I right clicked and said view source code, I see _ctl1_ is added to txtpath. If i use "_ctl1_txtPath" then it works. why is it happening like this.
 
Robby said:
You need to give an ID to your controls, otherwise they will be named automaticaly

Yes I gave an id.

<asp:textbox ID="txtPath" Visible=False Runat=server></asp:textbox>

and in javascript:
var v = document.getElementById("txtPath").value;

It still adds _ctl1_ to txtpath
 
Last edited:
That's why, what is your user control name in your aspx page?
If I not mistaken, the control in user control when place it to aspx page, the name will automatic change base on [user control name]_[original name], and the Id is [user control name]:[original name]
 
bungpeng said:
That's why, what is your user control name in your aspx page?
If I not mistaken, the control in user control when place it to aspx page, the name will automatic change base on [user control name]_[original name], and the Id is [user control name]:[original name]

for example:
my user control is uc1 and text box id, inside uc1 is txt1. I am writing a javascript function in side uc1 control. uc1 is placed inside page1.aspx.

function getMessage () {
var v1 = document.getElementById("uc1_txt1").value;
alert(v1);
}

is this correct if yes it still gives me error.
 
Back
Top