How to hiddenly pass parameters to a web user control ?

Discussion in 'ASP .Net' started by craigkenisston, Feb 27, 2005.

  1. Hi,

    I have a web user control that displays "items" by user, by category,
    newest "items", etc. It works very well and does what I want, this is
    done with parameters in the page that holds the control.

    However, now I want to put this web control on the main page and I
    don't want the main page to look "default.aspx?items=newest", for
    example, since it would look a bit ugly.

    Any idea or suggested approach to do this ?
     
    craigkenisston, Feb 27, 2005
    #1
    1. Advertisements

  2. craigkenisston

    Wilco Bauwer Guest

    I see 2 solutions:
    - URL rewriting. Allows you to rewrite paths like /newest to
    default.aspx?items=newest. This makes it totally transparent for the
    end-user.
    - Use postbacks/hidden state to pass parameters around and display
    content based on those parameters.

    I would certainly not use postbacks for this for several reasons (one
    of them is the ugly back button behaviour, another is bookmarks, etc).
    Url rewriting is probably the way to go. You can do a search on google
    for one - there are several free downloads. You can also implement your
    own, by for example implementing a custom httpmodule which rewrites a
    path.

    HTH.
     
    Wilco Bauwer, Feb 27, 2005
    #2
    1. Advertisements

  3. Instead of having the user control read the parameter from the
    querystring, why not have it expose a property that the containing page
    can set?

    In your control you would have a property:

    // use the 'items' variable everywhere you used to use the querystring value
    private string items;
    public string Items { get { return items; } set { items = value; } }

    Now in the main page, you can either set the property programmatically:

    myUserControl.Items = "newest"

    Or declaratively in the HTML:

    <uc1:MyUserControl id="myUserControl" runat="server" Items="newest" />


    -Joshua Flanagan
    http://flimflan.com/blog
     
    Joshua Flanagan, Feb 28, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.