ASP.NET equivallent to document.getElementById

  • Thread starter Thread starter Ferret Face
  • Start date Start date
F

Ferret Face

Hi, Folks!

Does ASP.NET have an equivallent to JavaScript's getElementById?

I am saving the name of an object in a hidden textbox (as a string obviously) because I cannot use session objects.

Thx.
 
Are you looking for how to get a control by its ID from code behind?

the code would be

this.FindControl("txtHiddenName")
 
Just keep in mind that getElementById() will search at any depth from the
current node. FindControl() will only look at the current level, unless you
use the fully quantified id.

for example, if you have a textbox within a user control, and do:

Page.FindControl("myTextBox")

it'll return null.

if you do myUserControl.FindControl("myTextBox") it'll return the textbox.

if you do Page.FindControl("myUserControl_MyTextBox") it'll return the
control (well, that's not what it'll actually be, but you get the idea...)

Karl
 
Woohoo!

That worked.

I ended up having to use:

Dim myTextBox as TextBox =
Page.FindControl("myForm").FindControl("myPanel").FindControl(objName)

Thanks.
 
Back
Top