Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > RegisterHiddenField question.

Reply
Thread Tools

RegisterHiddenField question.

 
 
ashish
Guest
Posts: n/a
 
      03-10-2005
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

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      03-10-2005
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


--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


"ashish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      03-11-2005
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

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> 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
>
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
>
> "ashish" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re-RegisterHiddenField Cliff Harris ASP .Net 0 11-05-2003 04:33 PM
RegisterHiddenField does not work inside .ascx components Francis ASP .Net 0 11-03-2003 01:01 PM
RegisterHiddenField and trace Kevin Spencer ASP .Net 2 10-22-2003 01:39 PM
EVENTTARGET EVENTARGUMENT RegisterHiddenField MeDhanush ASP .Net 1 08-28-2003 05:23 AM
RegisterHiddenField to Capture Enter Resetting Application Matthew Wieder ASP .Net 1 07-22-2003 06:04 AM



Advertisments