Results 1 to 4 of 4

Thread: Pass querystring to user control?

  1. #1
    STEVESKI07 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2007
    Posts
    17
    Reputation
    59

    Pass querystring to user control?

    I'm trying to pass a querystring to a dynamically loaded user control and I'm getting an error saying that it is not a valid virtual path when I put on the querystring parameters. If I take out the querystring parameters it is working fine. Does anybody know of any way to do this?

    Here is my code:
    Code:
    Dim graphControl As Control
    graphControl = LoadControl("~/User_Controls/BarGraph.ascx?id=CategoryCount")
    plcGraph.Controls.Add(graphControl)
    I know I could just use session variables if this is not possible, but is there any better way of doing this?

  2. #2
    demausdauth is offline VB.NET Forum Master
    .NET Framework
    .NET 2.0
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    281
    Reputation
    263
    You don't pass the querystring to the usercontrol, instead when the user control loads the querystring is available to it through Request.QueryString. In other words, in the PageLoad event of the user control you can access the QueryString.

  3. #3
    STEVESKI07 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2007
    Posts
    17
    Reputation
    59
    I'm trying to pass a value from the parent page to the user control. It isn't a querystring value in the parent page, so I will not be able to access it that way. I can just use the FindControl method to retrieve the value from the parent page, but the controls may be named differently on different pages so I'd rather not go that route.

  4. #4
    demausdauth is offline VB.NET Forum Master
    .NET Framework
    .NET 2.0
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    281
    Reputation
    263
    a session variable sounds like the best option -- you could try a public property on the user control although i haven't much experience with those.

Bookmarks

Posting Permissions

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

Search Engine Optimization by vBSEO