Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do you pass an ascx user control a variable??? Help please

Reply
Thread Tools

How do you pass an ascx user control a variable??? Help please

 
 
simon
Guest
Posts: n/a
 
      09-07-2006
hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0
i have a web app that i'm i have a user control that displays a simple
1 row table as the header of the page. the user control takes one
input variable, the string that will be displayed as the title of the
page. example call:
<uc1:Header runat=server ID="ucHeader" Title="Home Page" />

what i am looking to do on a certain page is have the "title" value be
dynamic, in that i will pull the string from the database and pass
that to the user control.
i have the process working just fine if i'm passing it into a label,
but the user control is not receiving the setting of this value. i'm
assuming that controls on a page are process first before the page.

how would i do this? example code would be very much appreciated!!
thank you.


 
Reply With Quote
 
 
 
 
Matt MacDonald
Guest
Posts: n/a
 
      09-07-2006
Hi Simon,
You need to specify a property in your control as well as a variable to
hold the value. For example:
Dim _Title As String
Property Title() As String
Get
Return _Title
End Get
Set(ByVal value As String)
_Title = value
End Set
End Property

Then, from within your control you can use _Title just like any other
variable. You can also reference this in your page code by doing
mycontrol.Title = "something" assuming that you add the appropriate
mycontrol declaration.

Thanks,
Matt

"simon" <> wrote in message
news:...
> hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0
> i have a web app that i'm i have a user control that displays a simple
> 1 row table as the header of the page. the user control takes one
> input variable, the string that will be displayed as the title of the
> page. example call:
> <uc1:Header runat=server ID="ucHeader" Title="Home Page" />
>
> what i am looking to do on a certain page is have the "title" value be
> dynamic, in that i will pull the string from the database and pass
> that to the user control.
> i have the process working just fine if i'm passing it into a label,
> but the user control is not receiving the setting of this value. i'm
> assuming that controls on a page are process first before the page.
>
> how would i do this? example code would be very much appreciated!!
> thank you.
>
>



 
Reply With Quote
 
 
 
 
YurikoEX@gmail.com
Guest
Posts: n/a
 
      09-07-2006
I would use session variables. Easy quick and affective. set the
session in the main page like, Session["Title"] = "My New Title" then
in the control have the control look for Session["Title]" != null then
set the title to the session variable

simon wrote:
> hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0
> i have a web app that i'm i have a user control that displays a simple
> 1 row table as the header of the page. the user control takes one
> input variable, the string that will be displayed as the title of the
> page. example call:
> <uc1:Header runat=server ID="ucHeader" Title="Home Page" />
>
> what i am looking to do on a certain page is have the "title" value be
> dynamic, in that i will pull the string from the database and pass
> that to the user control.
> i have the process working just fine if i'm passing it into a label,
> but the user control is not receiving the setting of this value. i'm
> assuming that controls on a page are process first before the page.
>
> how would i do this? example code would be very much appreciated!!
> thank you.


 
Reply With Quote
 
simon
Guest
Posts: n/a
 
      09-07-2006
hello matt,
thanks for the reply. what you described at the end ...
mycontrol.Title = "something"
is exactly what i was looking to do.
where would the property definition go? is that in the ascx code
behind?
also, once this is done, would the normal way of calling the control
still work? like having a title hard coded in the call (as they are
now)
thanks again

On Thu, 7 Sep 2006 11:24:59 -0400, "Matt MacDonald"
<> wrote:

>Hi Simon,
> You need to specify a property in your control as well as a variable to
>hold the value. For example:
>Dim _Title As String
>Property Title() As String
> Get
> Return _Title
> End Get
> Set(ByVal value As String)
> _Title = value
> End Set
>End Property
>
>Then, from within your control you can use _Title just like any other
>variable. You can also reference this in your page code by doing
>mycontrol.Title = "something" assuming that you add the appropriate
>mycontrol declaration.
>
>Thanks,
> Matt
>
>"simon" <> wrote in message
>news:.. .
>> hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0
>> i have a web app that i'm i have a user control that displays a simple
>> 1 row table as the header of the page. the user control takes one
>> input variable, the string that will be displayed as the title of the
>> page. example call:
>> <uc1:Header runat=server ID="ucHeader" Title="Home Page" />
>>
>> what i am looking to do on a certain page is have the "title" value be
>> dynamic, in that i will pull the string from the database and pass
>> that to the user control.
>> i have the process working just fine if i'm passing it into a label,
>> but the user control is not receiving the setting of this value. i'm
>> assuming that controls on a page are process first before the page.
>>
>> how would i do this? example code would be very much appreciated!!
>> thank you.
>>
>>

>


 
Reply With Quote
 
Matt MacDonald
Guest
Posts: n/a
 
      09-08-2006
The property definition would need to go in the codebehind for the control.

As far as calling the control, you would need to drag it into your page html
like you said in your first post:
<uc1:Header runat=server ID="ucHeader" Title="Home Page" />

In VS2003 you need to add the control declaration to the codebehind of your
page as well in order to be able to reference it:
Protected WithEvents ucHeader as Header <-- This would go in the code behind
up where the rest of the control definitions are.

See if that works for you.

Thanks,
Matt

"simon" <> wrote in message
news:...
> hello matt,
> thanks for the reply. what you described at the end ...
> mycontrol.Title = "something"
> is exactly what i was looking to do.
> where would the property definition go? is that in the ascx code
> behind?
> also, once this is done, would the normal way of calling the control
> still work? like having a title hard coded in the call (as they are
> now)
> thanks again
>
> On Thu, 7 Sep 2006 11:24:59 -0400, "Matt MacDonald"
> <> wrote:
>
>>Hi Simon,
>> You need to specify a property in your control as well as a variable to
>>hold the value. For example:
>>Dim _Title As String
>>Property Title() As String
>> Get
>> Return _Title
>> End Get
>> Set(ByVal value As String)
>> _Title = value
>> End Set
>>End Property
>>
>>Then, from within your control you can use _Title just like any other
>>variable. You can also reference this in your page code by doing
>>mycontrol.Title = "something" assuming that you add the appropriate
>>mycontrol declaration.
>>
>>Thanks,
>> Matt
>>
>>"simon" <> wrote in message
>>news:. ..
>>> hello. relatively new to vb.net, i'm using VS 2003 and .net 2.0
>>> i have a web app that i'm i have a user control that displays a simple
>>> 1 row table as the header of the page. the user control takes one
>>> input variable, the string that will be displayed as the title of the
>>> page. example call:
>>> <uc1:Header runat=server ID="ucHeader" Title="Home Page" />
>>>
>>> what i am looking to do on a certain page is have the "title" value be
>>> dynamic, in that i will pull the string from the database and pass
>>> that to the user control.
>>> i have the process working just fine if i'm passing it into a label,
>>> but the user control is not receiving the setting of this value. i'm
>>> assuming that controls on a page are process first before the page.
>>>
>>> how would i do this? example code would be very much appreciated!!
>>> thank you.
>>>
>>>

>>

>



 
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: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Multiple *.ascx files with a single *.ascx.cs in VS.NET 2003 Holger (David) Wagner ASP .Net 2 07-03-2004 09:23 AM
datasource of child .ascx not visible to parent .ascx Joe ASP .Net Web Controls 1 02-16-2004 07:27 AM
can a dg be added to an ascx? ascx call a ws? Jason Shohet ASP .Net 1 11-10-2003 07:08 PM
[ASCX] Add an ascx in a webcontrol... Quentin ASP .Net 1 07-29-2003 07:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57