|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do you pass an ascx user control a variable??? Help pleasehello. 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. 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 Show quote "simon" <m*@here.com> wrote in message news:ltc0g2d3hj3tg22hv3qbe32rpr545hd487@4ax.com... > 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. > > 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" <matts***@hotmail.com> wrote: Show quote >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" <m*@here.com> wrote in message >news:ltc0g2d3hj3tg22hv3qbe32rpr545hd487@4ax.com... >> 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. >> >> > 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 Show quote "simon" <m*@here.com> wrote in message news:tdi0g25ohp5v708382ntbu0l5ptvl8eha8@4ax.com... > 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" > <matts***@hotmail.com> 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" <m*@here.com> wrote in message >>news:ltc0g2d3hj3tg22hv3qbe32rpr545hd487@4ax.com... >>> 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. >>> >>> >> > 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: Show quote > 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. |
|||||||||||||||||||||||