Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mladen Macanovic 22 posts 45 karma points
    Nov 29, 2010 @ 15:48
    Mladen Macanovic
    0

    Search control

    I tried to find the solution for my problem but cannot find it.

    I have two .NET controls. First control, let's call it C1, have some search parameters and submit button, and another control, we'l call it C2, is just a simple repeater that needs to show the data based on the parameters selected and/or entered in the first control.

    The problem is that I don't know how to pass the parameter from control C1 to control C2 so that C2 can show show searched data. Is this even possible to pass the parameters from one control to another or do I need to mess with viewstate or session to accomplish this?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 29, 2010 @ 16:03
    Lee Kelleher
    0

    Hi Mladen,

    There are a few ways to pass parameters between .NET controls.  Usually for search results, the query and other parameters can be set in the URL's querystring. You can then use the Request.QueryString collection to get the values.

    If you don't want to use the querystring, then you could use a HttpContext.Item?  They are only available for the life-cycle of the page, but you shouldn't need them beyond.

    I wouldn't recommend using Sessions, unless you wanted to persist the search/query across multiple page requests?

    Cheers, Lee.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Nov 29, 2010 @ 16:10
    Michael Latouche
    1

    Hi Mladen,

    One solution I think of, is for example to provide a public "get" property that returns the entered value for each search parameter on the control C1. The control C2 can then access those properties on Postback and then build its search query.

    Hope this helps!

    Cheers,

    Michael.

  • Mladen Macanovic 22 posts 45 karma points
    Nov 29, 2010 @ 16:58
    Mladen Macanovic
    0

    Hi Lee,

    As you suggested I tried to use HttpContext and no success. Maybe i'm missing something.

    First I set the HttpContext value in the control C1 on button click.

    Context.Items["somevalue"] = "xyz";

    then when I try to read it in C2 using

    string xyz = Context.Items["somevalue"];

    nothing happens, it is null.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 29, 2010 @ 17:07
    Lee Kelleher
    0

    Hi Mladen,

    Really difficult to say why its returning null... would need to see more better code snippet.

    At a guess it could be due to the stage of the ASP.NET life-cycle? As in its being set in C1's OnClick, and C2's OnLoad has already triggered... not sure though, would need to see more code.

    Have you tried Mike's suggestion of exposing a public property in C2? (its a good suggestion)

    Cheers, Lee.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 29, 2010 @ 23:14
    Aaron Powell
    0

    If you use WebForms MVP you can use cross-presenter messaging: http://wiki.webformsmvp.com/index.php?title=SC009

Please Sign in or register to post replies

Write your reply to:

Draft