Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Pass Variable Value To User Control From Host Page

    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
    Code:
            Public mainSkin As String
    
            Public Property ucSkin() As String
                Get
                    Return ucSkin
                End Get
                Set(ByVal value As String)
                    mainSkin = value
                End Set
            End Property
    Here is the code from the host page
    Code:
    <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:
    Code:
    <jsFlsAd:flsAd  id="FlsAd" runat="server" ucSkin= "blk"></jsFlsAd:flsAd>
    That will work.
    Can someone help me understand what I am doing wrong?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I used FlsAd.ucSkin = varSkin in the Page_Init Sub and it worked. Thanks for your help.

  • #4
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The function is very useful for me! thanks guy!

  • #5
    New to the CF scene
    Join Date
    Mar 2010
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    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

    Page.Form.FindControl("FlsAd").DataBind()

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

    Hope this helps
    Graham


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •