是什么把更新面板内的多个控制的正确方法? [英] What is the correct way to put multiple controls inside update panel?

查看:185
本文介绍了是什么把更新面板内的多个控制的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含3到4下拉控件和2 datepickers,现在当下拉控件值选择了一个登记表(改变的selectedIndex被解雇)
然后我不希望我的网页回发。

I have one registration form which contains 3 to 4 dropdown controls and 2 datepickers and now when dropdown controls value are selected(selectedindex change are fired) then i dont want my page to postback.

我必须使用更新面板停止后的这种行为就像如下:

I have use update panel to stop this behaviour of post like below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

      <%--Update Panel for date picker%>
      <asp:UpdatePanel ID="UpdatePanelDatepicker" runat="server">
                    <ContentTemplate>
                      <telerik:RadDatePicker ID="rdpDate1" runat="server">
                      </telerik:RadDatePicker>
                    </ContentTemplate>
      </asp:UpdatePanel>

       <%--Update Panel for Dropdown--%>
       <asp:UpdatePanel ID="updatepaneldata" runat="server"> 
                      <ContentTemplate>
                     <telerik:RadComboBox ID="ddlCountry" runat="server">
                      </telerik:RadComboBox>
                    </ContentTemplate>
      </asp:UpdatePanel>


  </ContentTemplate>
    </asp:UpdatePanel>

所以,我只是想问问这是把未更新面板??

So i just wanted to ask that is this correct way to put multiple controls under update panels??

推荐答案

订阅的客户端 initializeRequest 的Ajax事件。在这种情况下,如果我们需要,我们可以取消一个ajax回发。

Subscribe to ajax event of initializeRequest on client-side. In this event we can cancel an ajax postback if we need to.

异步请求的处理开始之前的initializeRequest方法上升。您可以使用此事件来取消回发。

The initializeRequest method is raised before processing of the asynchronous request starts. You can use this event to cancel a postback.

在这种情况下,我们将检查异步回发正由于发起 ddlCountry ,如果是那么我们取消了ajax后回来,无后恢复运行。

In this event, we will check if an async postback is being initiated due to ddlCountry, and if yes then we cancel the ajax post back so no post back occurs.

解决你的问题只是做以下添加下面的JavaScript ASPX页的在下面code时,页面加载方法是自动ASP.Net框架于客户端时,浏览器加载网页和之后所有的脚本已经被加载以及所有的客户端对象称为创建。

To solve your problem just do the following : Add following JavaScript to your aspx page. In code below, the pageLoad method is automatically called by ASP.Net Framework on client-side when browser loads the page and after all scripts have been loaded as well as all client-side objects created.

JavaScript来取消组合框后回

<script type="text/javascript">
function pageLoad()
{
     Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CancelComboBoxPostback);
}

function CancelComboBoxPostback(sender, args)
{
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'ddlCountry') {
         args.set_cancel(true);
    }
 }
</script>

下面只是我们的建议和解决您的具体问题的不是一部分:另外,我建议远离嵌套在更新面板远,因为这可能会导致意外的结果,如果开发商不知道更新面板如何嵌套的工作。在你的情况,一个更新面板应该足够了如下代替嵌套更新面板的标记,你有你原来的标记使用。

The following is only a recommendation and not a part of the solution to your specific problem: Also, I would recommend to stay away from nested update panels as this can cause unexpected results if developer is not aware of how nested update panels work. In your situation, a single update panel should suffice as in markup below instead of nested update panels that you have used in your original markup.

标记没有嵌套的更新面板

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
              <telerik:RadDatePicker ID="rdpDate1" runat="server">
              </telerik:RadDatePicker>

              <telerik:RadComboBox ID="ddlCountry" runat="server">
              </telerik:RadComboBox>
    </ContentTemplate>
</asp:UpdatePanel>

这篇关于是什么把更新面板内的多个控制的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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