Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Any Way to Limit Instances of a Web User Control Element?

Reply
Thread Tools

Any Way to Limit Instances of a Web User Control Element?

 
 
Jonathan Wood
Guest
Posts: n/a
 
      05-04-2009
I'm creating a Web User Control. It needs to include a few component
controls. But one of those component controls, a HiddenField control, should
only appear once on the entire page (at least with that name).

I'm not sure this is doable, but does anyone know if there's any way to
limit the number of instances on a page of a component of a Web User Control
to one, even if there are multiple instances of the Web User Control?

Thanks for any thoughts.

Jonathan

 
Reply With Quote
 
 
 
 
Joe Fawcett
Guest
Posts: n/a
 
      05-04-2009
Can't you just implement INamingContainer on the user control and then the
hidden field will always have a unique name?

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm creating a Web User Control. It needs to include a few component
> controls. But one of those component controls, a HiddenField control,
> should only appear once on the entire page (at least with that name).
>
> I'm not sure this is doable, but does anyone know if there's any way to
> limit the number of instances on a page of a component of a Web User
> Control to one, even if there are multiple instances of the Web User
> Control?
>
> Thanks for any thoughts.
>
> Jonathan
>




 
Reply With Quote
 
 
 
 
William Niver
Guest
Posts: n/a
 
      05-04-2009
Howdy Jonathan!

Pop this logic somewhere in your user control.

If (Not
Me.Page.ClientScript.IsStartupScriptRegistered("Hi ddenFieldIsRegistered"))
Then
Dim hdn_Main As New HiddenField
With hdn_Main
.ID = "hdn_Main"
End With
Me.Page.Form.Controls.Add(hdn_Main)
Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(),
"HiddenFieldIsRegistered", "Yes", True)
End If

"Jonathan Wood" wrote:

> I'm creating a Web User Control. It needs to include a few component
> controls. But one of those component controls, a HiddenField control, should
> only appear once on the entire page (at least with that name).
>
> I'm not sure this is doable, but does anyone know if there's any way to
> limit the number of instances on a page of a component of a Web User Control
> to one, even if there are multiple instances of the Web User Control?
>
> Thanks for any thoughts.
>
> Jonathan
>
>

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      05-04-2009
I'm not familiar with INamingContainer but I need exactly one instance of
the HiddenField with a pre-determined name.

Thanks.

Jonathan

"Joe Fawcett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can't you just implement INamingContainer on the user control and then the
> hidden field will always have a unique name?
>
> --
>
> Joe Fawcett (MVP - XML)
> http://joe.fawcett.name
> "Jonathan Wood" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I'm creating a Web User Control. It needs to include a few component
>> controls. But one of those component controls, a HiddenField control,
>> should only appear once on the entire page (at least with that name).
>>
>> I'm not sure this is doable, but does anyone know if there's any way to
>> limit the number of instances on a page of a component of a Web User
>> Control to one, even if there are multiple instances of the Web User
>> Control?
>>
>> Thanks for any thoughts.
>>
>> Jonathan
>>

>
>
>


 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      05-04-2009
<g>

You know, I kept thinking last night that what I needed was something like
ClientScript except for HTML instead of javascript!

I just put this together and it appears to be working perfectly.

I did get an error that "Yes" was undefined so I changed it to
Page.ClientScript.RegisterStartupScript(typeof(Pag e),
"HiddenFieldIsRegistered", "", false); and that seems okay.

Also, I like working with ClientScript because I plan to use it here for
other stuff in my control as well. (I'm thinking of writing client script to
copy the control-specific value to the one-and-only hidden field when my
control is clicked.)

Thanks again!

Jonathan

"William Niver" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Howdy Jonathan!
>
> Pop this logic somewhere in your user control.
>
> If (Not
> Me.Page.ClientScript.IsStartupScriptRegistered("Hi ddenFieldIsRegistered"))
> Then
> Dim hdn_Main As New HiddenField
> With hdn_Main
> .ID = "hdn_Main"
> End With
> Me.Page.Form.Controls.Add(hdn_Main)
> Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(),
> "HiddenFieldIsRegistered", "Yes", True)
> End If
>
> "Jonathan Wood" wrote:
>
>> I'm creating a Web User Control. It needs to include a few component
>> controls. But one of those component controls, a HiddenField control,
>> should
>> only appear once on the entire page (at least with that name).
>>
>> I'm not sure this is doable, but does anyone know if there's any way to
>> limit the number of instances on a page of a component of a Web User
>> Control
>> to one, even if there are multiple instances of the Web User Control?
>>
>> Thanks for any thoughts.
>>
>> Jonathan
>>
>>


 
Reply With Quote
 
William Niver
Guest
Posts: n/a
 
      05-04-2009
one thing to be wary of when using the typeof(page) when using the script
registration is that it won't work when inside of an updating update panel
except on the initial page load.

After that, there is no page object to attach it to, so it bombs. In those
cases, attach it to a control which is included in the update and all will be
well and good.

William

"Jonathan Wood" wrote:

> <g>
>
> You know, I kept thinking last night that what I needed was something like
> ClientScript except for HTML instead of javascript!
>
> I just put this together and it appears to be working perfectly.
>
> I did get an error that "Yes" was undefined so I changed it to
> Page.ClientScript.RegisterStartupScript(typeof(Pag e),
> "HiddenFieldIsRegistered", "", false); and that seems okay.
>
> Also, I like working with ClientScript because I plan to use it here for
> other stuff in my control as well. (I'm thinking of writing client script to
> copy the control-specific value to the one-and-only hidden field when my
> control is clicked.)
>
> Thanks again!
>
> Jonathan
>
> "William Niver" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > Howdy Jonathan!
> >
> > Pop this logic somewhere in your user control.
> >
> > If (Not
> > Me.Page.ClientScript.IsStartupScriptRegistered("Hi ddenFieldIsRegistered"))
> > Then
> > Dim hdn_Main As New HiddenField
> > With hdn_Main
> > .ID = "hdn_Main"
> > End With
> > Me.Page.Form.Controls.Add(hdn_Main)
> > Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(),
> > "HiddenFieldIsRegistered", "Yes", True)
> > End If
> >
> > "Jonathan Wood" wrote:
> >
> >> I'm creating a Web User Control. It needs to include a few component
> >> controls. But one of those component controls, a HiddenField control,
> >> should
> >> only appear once on the entire page (at least with that name).
> >>
> >> I'm not sure this is doable, but does anyone know if there's any way to
> >> limit the number of instances on a page of a component of a Web User
> >> Control
> >> to one, even if there are multiple instances of the Web User Control?
> >>
> >> Thanks for any thoughts.
> >>
> >> Jonathan
> >>
> >>

>
>

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      05-04-2009
Okay, perhaps I'll change it to this.GetType(). I thought I read somewhere
that there were issues doing anything but Page in most cases. Unfortunately,
I don't recall why. There seemed to be some confusion regarding this.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
http://www.softcircuits.com/blog/

"William Niver" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> one thing to be wary of when using the typeof(page) when using the script
> registration is that it won't work when inside of an updating update panel
> except on the initial page load.
>
> After that, there is no page object to attach it to, so it bombs. In
> those
> cases, attach it to a control which is included in the update and all will
> be
> well and good.
>
> William
>
> "Jonathan Wood" wrote:
>
>> <g>
>>
>> You know, I kept thinking last night that what I needed was something
>> like
>> ClientScript except for HTML instead of javascript!
>>
>> I just put this together and it appears to be working perfectly.
>>
>> I did get an error that "Yes" was undefined so I changed it to
>> Page.ClientScript.RegisterStartupScript(typeof(Pag e),
>> "HiddenFieldIsRegistered", "", false); and that seems okay.
>>
>> Also, I like working with ClientScript because I plan to use it here for
>> other stuff in my control as well. (I'm thinking of writing client script
>> to
>> copy the control-specific value to the one-and-only hidden field when my
>> control is clicked.)
>>
>> Thanks again!
>>
>> Jonathan
>>
>> "William Niver" <(E-Mail Removed)> wrote in message
>> news(E-Mail Removed)...
>> > Howdy Jonathan!
>> >
>> > Pop this logic somewhere in your user control.
>> >
>> > If (Not
>> > Me.Page.ClientScript.IsStartupScriptRegistered("Hi ddenFieldIsRegistered"))
>> > Then
>> > Dim hdn_Main As New HiddenField
>> > With hdn_Main
>> > .ID = "hdn_Main"
>> > End With
>> > Me.Page.Form.Controls.Add(hdn_Main)
>> > Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(),
>> > "HiddenFieldIsRegistered", "Yes", True)
>> > End If
>> >
>> > "Jonathan Wood" wrote:
>> >
>> >> I'm creating a Web User Control. It needs to include a few component
>> >> controls. But one of those component controls, a HiddenField control,
>> >> should
>> >> only appear once on the entire page (at least with that name).
>> >>
>> >> I'm not sure this is doable, but does anyone know if there's any way
>> >> to
>> >> limit the number of instances on a page of a component of a Web User
>> >> Control
>> >> to one, even if there are multiple instances of the Web User Control?
>> >>
>> >> Thanks for any thoughts.
>> >>
>> >> Jonathan
>> >>
>> >>

>>
>>


 
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
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
is there any way i can set a time limit for user input in a javaprogram? Avi Java 2 04-11-2008 11:32 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Creating multiple instances of a Web User Control. Phobos ASP .Net Web Controls 0 08-16-2004 06:41 AM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM



Advertisments