Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Note: I think as a programmer not as a human, so use my answer at your will
Posted (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 by kaisersoze
Note: I think as a programmer not as a human, so use my answer at your will
Posted

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]

Posted
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.

Note: I think as a programmer not as a human, so use my answer at your will

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...