kaisersoze Posted April 27, 2004 Posted April 27, 2004 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. Quote Note: I think as a programmer not as a human, so use my answer at your will
Moderators Robby Posted April 27, 2004 Moderators Posted April 27, 2004 You need to give an ID to your controls, otherwise they will be named automaticaly Quote Visit...Bassic Software
kaisersoze Posted April 27, 2004 Author Posted April 27, 2004 (edited) You need to give an ID to your controls' date=' otherwise they will be named automaticaly[/quote'] 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 Edited April 27, 2004 by kaisersoze Quote Note: I think as a programmer not as a human, so use my answer at your will
Cassio Posted April 27, 2004 Posted April 27, 2004 Is your textbox inside a datagrid, datalist or something like it? Quote Stream of Consciousness (My blog)
kaisersoze Posted April 27, 2004 Author Posted April 27, 2004 No. it is in a user control and the usercontrol is called in a .aspx page. Quote Note: I think as a programmer not as a human, so use my answer at your will
bungpeng Posted April 28, 2004 Posted April 28, 2004 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] Quote
kaisersoze Posted April 29, 2004 Author Posted April 29, 2004 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. Quote Note: I think as a programmer not as a human, so use my answer at your will
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.