RegisterHiddenField question.

A

ashish

If i want to add a hidden field on the page, how can i check whether
that hidden field exists ?

for example if i do

If Page.FindControl("myhiddenfield") Is Nothing Then
Page.RegisterHiddenField("myhiddenfield", "hidden")
End If


Dim myHiddenField As HtmlInputHidden = Page.FindControl("myhiddenfield")
** this line would throw error


how can i know that the hidden field is there before trying to add it ?

TIA
-ashish
 
K

Karl Seguin

Ashish:
Page.RegisterHiddenField doesn't create a server side control, it just
creates a plain-old <input type="hidden">..so
Page.FindControl("myhiddenField") will never find anything....

If you call RegisterHiddenField twice with the same id, it'll only register
the field once, so:
Page.RegisterHiddenField("myhiddenfield", "hidden")
Page.RegisterHiddenField("myhiddenfield", "hidden")

there'll only be 1 myHiddenField

There's no way to tell which hidden fields have been registered this
way...on postback you can use Request.Form("myhiddenField") to get the
information though

You could always create a server control via:
dim myHiddenField as new HtmlInputHidden()
somePlaceHolder.Controls.Add(myHiddenField)


Karl
 
W

William F. Robertson, Jr.

If you register the same field twice with two different values, the first
value takes precedence.

Page.RegisterHiddenField( "myHiddenField", "value1" );
Page.RegisterHiddenField( "myHiddenField", "value2" );

"value1" will be rendered. The second call is ignored.

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top