标识导致回传控制 [英] Identifying control that caused postback

查看:153
本文介绍了标识导致回传控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表中选择回传(使用AJAX更新面板)的页面。基于下拉选择,是动态生成的页面上的用户界面的其余部分。动态UI绘制在页面加载关于提交按钮点击获取值。我现在面临的问题是,上下拉变化,在两个回发似乎发生,其中一个绘制绘制改变的UI(因此产生不一致)的原始的用户界面和一个。如何处理这个问题。有什么办法找出哪个控件导致回发,这样我就可以重绘UI回发时发生,由于选择更改/提交按钮点击。

I have a page that postbacks on a dropdown list selection (using AJAX update panel). Based on the dropdown selection, the rest of the UI on the page is generated dynamically. The dynamic UI is drawn on page load for fetching values on Submit button click. The problem I am facing is that on dropdown change, two postbacks seem to happen, one which draws the original UI and one that draws the changed UI (thus creating inconsistency). How to deal with this. Is there any way to figure out which control caused the postback, so that I can redraw UI when postback happens due to selection change/submit button click.

编辑:错过了问题的一个重要点。为更新面板的触发下拉列表中的的SelectionChanged 事件。这会导致额外的回传。

Missed an important point in question. The trigger for update panel is SelectionChanged event of dropdown list. That causes the additional postback.

推荐答案

您可以检查回发,然后做..

You can check for a postback and then do..

if (IsPostBack)
{ 
  var targetID = Request.Form["__EVENTTARGET"];
}

编辑:您可以通过执行获得的实际控制人。

You can get the actual control by doing..

if (targetID != null && targetID != string.Empty)
{
    var targetControl = this.Page.FindControl(targetID);
}

这篇关于标识导致回传控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆