简体   繁体   中英

Call an event handler on another page

Simple question here, but I've got a nagging feeling that there's a more interesting solution than the one I've chosen:

Page Two consists of a dropdown, and the change event is handled to execute some query.

protected void ddlSavedQueries_SelectedIndexChanged(object sender, EventArgs e)
{
    /* stuff happens */
}

Page One is a home page, where I'm providing another version of that dropdown. I'd like the change event in this case to redirect control to Page Two, and then execute the event handler.

My cheap solution is just a Redirect with a querystring value that is handled on page load. Am I missing a more interesting approach?

If you don't want to ugly things up with a querystring value, I suppose you could put something in Session and pick it up on Page_Load of the second page (and then clear it out of Session ). Not exactly an awesome improvement though.

Does the same page always get displayed when you change that dropdown? If so, consider using client side javascript to redirect to the correct page, then fire any logic on the subsequent page in the page_load event. Example using jQuery:

$(function() {

    $("select.classyouneedtodefine").change(function() {
        document.location.href = "somepage.aspx?value=" + $(this).val();
    });

});

haven't tested the above...just shooting from the hip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM