简体   繁体   English

在另一页上调用事件处理程序

[英]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: 这里有一个简单的问题,但是我有点ing不安,觉得比我选择的解决方案更有趣的解决方案:

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 ). 如果您不想用querystring值弄糟,我想您可以在Session放一些东西,然后在第二页的Page_Load中拾取它(然后从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. 如果是这样,请考虑使用客户端javascript重定向到正确的页面,然后在page_load事件中的后续页面上触发任何逻辑。 Example using jQuery: 使用jQuery的示例:

$(function() {

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

});

haven't tested the above...just shooting from the hip 尚未测试以上内容...只是从臀部射击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 另一个页面的通话事件 - Call event from another page 需要先调用Silverlight Handler事件,然后在页面提交时调用服务器端事件 - Need to call Silverlight Handler event and then serverside event on Page submit 从另一个事件处理程序调用事件处理程序方法并传递额外的参数 - Call event handler method from another event handler and pass extra parameters 有没有一种方法可以在另一个类中创建事件处理程序代码,然后调用它 - Is there a way to create an event handler code in another class and just call it 如何从一个控件调用事件处理程序到另一个控件? - How to call an event handler from one control to the another control? 从宿主页面在用户控件中调用事件处理程序 - Call an event handler in a user control from host page C#WPF为另一个页面中的处理程序的窗口添加KeyUp事件 - C# WPF add KeyUp event for window with a handler in another page 在另一个事件处理程序中调用事件处理程 - calling a event handler within another event handler? 如何从另一个处理程序调用/调用按钮单击事件处理程序? (C# ) - How Do I invoke/call a button click event handler form another handler? (c# ) 将一个事件处理程序添加到另一个 - Adding one event handler to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM