[英]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.