View Full Version : Pass Variable Value To User Control From Host Page

09-06-2005, 06:02 PM
I am trying to pass the value of a varible to a user control (code behind) from the host page of the user control. In the uc code behind I am using Get...Set to retrive the value and if I use a static string (i.e "blk") it works but I cannot get it to work using (<%#variable%>. Here is the code:

In the user control code behind

Public mainSkin As String

Public Property ucSkin() As String
Return ucSkin
End Get
Set(ByVal value As String)
mainSkin = value
End Set
End Property

Here is the code from the host page

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= "<%#varSkin%>"></jsFlsAd:flsAd>

Where varSkin is declared as Public in the code behind of the host page.

The above line does not work, however if I change it to:

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= "blk"></jsFlsAd:flsAd>

That will work.
Can someone help me understand what I am doing wrong?

09-06-2005, 06:47 PM
I saw that issue before I think.
Try not setting it there, but in page_load instead.

like in page_load, do
mainSkin.ucSkin = Request.QueryString("varSkin");
or however you're getting that variable.

09-06-2005, 07:36 PM
I used FlsAd.ucSkin = varSkin in the Page_Init Sub and it worked. Thanks for your help.

03-04-2010, 04:28 AM
The function is very useful for me! thanks guy!

03-08-2010, 11:35 PM

I've struggled with this problem in the past, and I have found that you need to run a bind on it

something like :-

<jsFlsAd:flsAd id="FlsAd" runat="server" ucSkin= "<%#varSkin%>"></jsFlsAd:flsAd>

and in the load event


There is a bit more of an explanation at http://programmingtips.co.uk/content/view/59/4/

Hope this helps