none
Updatepanel 内的 ModalPopupExtender 导致整页刷新,求教 RRS feed

  • 问题

  • 我在updatepanel里包了一个ModalPopupExtender  结果当ModalPopupExtender 所控制的panel按钮启动时整个页面重刷了一次,能局部刷吗?
    aspx文件
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    
    
    <head runat="server">
    
        <title></title>
    
        <style type="text/css">
    
           .modalBackground     
    
        {
    
            background-color:#ccc;    
    
            filter:alpha(opacity=60);    
    
            opacity:0.6;
    
        }
    
        .modalPopup 
    
        {    
    
            background-color:#ffffdd;    
    
            border-width:3px;    
    
            border-style:solid;    
    
            border-color:Gray;    
    
            padding:3px;    
    
            width:350px;
    
            height:200px;
    
        } 
    
     .noshow
    
     {
    
     	display:none;
    
     }     
    
        </style>
    
    </head>
    
    <body>
    
       
    
        <form id="form1" runat="server">
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
    
        </asp:ScriptManager>
    
        <div>
    
        
    
        <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
    
        <ContentTemplate>
    
        <div style="height: 37px">
    
        <asp:Button ID="bt1" runat="server" Text="1" />
    
        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>
    
        <asp:Button ID="bt2" runat="server" Text="2" />
    
        </div>
    
            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">
    
          
    
            <div class="modalPopup"><br /><br /><br />
    
                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>
    
                <br /><br/>
    
                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" onclick="AgreePano" 
    
                  />
    
                    <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />
    
                    
    
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
    
                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />
    
            </div>
    
           
    
        </asp:Panel>
    
        
    
        
    
         
    
        
    
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"        
    
            BackgroundCssClass="modalBackground"
    
            Enabled="True" 
    
            TargetControlID="bt1"
    
            PopupControlID = "PopupPanel"
    
            OkControlID = "bt_close"
    
            CancelControlID = "btnCancel"
    
            DropShadow="true" 
    
             BehaviorID="Panel1"       
    
            >
    
        </cc1:ModalPopupExtender>
    
        
    
        </ContentTemplate>
    
        </asp:UpdatePanel>
    
        
    
        </div>
    
        </form>
    
    </body>
    
    </html>

    cs文件

    using System;
    
    using System.Collections.Generic;
    
    using System.Linq;
    
    using System.Web;
    
    using System.Web.UI;
    
    using System.Web.UI.WebControls;
    
    
    
    public partial class Default8 : System.Web.UI.Page
    
    {
    
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
    
    
        }
    
        protected void AgreePano(object sender, EventArgs e)
    
        {
    
           
    
    
    
          
    
            try
    
            {
    
                tx1.Text = txt_newpano.Text;
    
            }
    
            catch (Exception err)
    
            {
    
               
    
            }
    
    
    
          
    
        }
    
    }
    
    
    2010年3月8日 3:11

答案


  •     <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">

        <ContentTemplate>

        <div style="height: 37px">

        <asp:Button ID="bt1" runat="server" Text="1" />

        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>

        <asp:Button ID="bt2" runat="server" Text="2" />

        </div>

            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">

         

            <div class="modalPopup"><br /><br /><br />

                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>

                <br /><br/>

                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" OnClientClick="show()" onclick="AgreePano"

                  />
                  <script language="javascript" type="text/javascript">

                      function show() {
                          var p = $find('Panel1');
                          p.hide();
                      }
                  </script>

                    <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />

                   

                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />

                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />

            </div>

          

        </asp:Panel>

       

       

        

       

     
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"       
            BackgroundCssClass="modalBackground"
            Enabled="True"
            TargetControlID="bt1"
            PopupControlID = "PopupPanel"
            OkControlID = "bt_close"
            CancelControlID = "btnCancel"
            DropShadow="true"
             BehaviorID="Panel1"      
            >
        </cc1:ModalPopupExtender>
       
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAgree" />
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>

        </asp:UpdatePanel>

    • 已标记为答案 scate233 2010年3月11日 8:18
    2010年3月8日 10:04

全部回复

  • 你这个问题是什么意思? ajax控件都是异步 我这测试没有出现  整个刷新
    2010年3月8日 8:10
  • 你这个问题是什么意思? ajax控件都是异步 我这测试没有出现  整个刷新

    我不要整页刷,只是要局部刷新,如果界面的东西多,就会连不该刷的也刷了,我只要updatepanel里头才刷新。
    2010年3月8日 8:37
  • 你这个问题是什么意思? ajax控件都是异步 我这测试没有出现  整个刷新

    我不要整页刷,只是要局部刷新,如果界面的东西多,就会连不该刷的也刷了,我只要updatepanel里头才刷新。

    你没有指定按钮触发updatepanel
    2010年3月8日 9:20
  • ASPX文件body变成



    <body>
      
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
       
        <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        <div style="height: 37px">
        <asp:Button ID="bt1" runat="server" Text="1" />
        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>
        <asp:Button ID="bt2" runat="server" Text="2" />
        </div>
            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">
         
            <div class="modalPopup"><br /><br /><br />
                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>
                <br /><br/>
                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" onclick="AgreePano"
                  />
                    <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />
                   
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />
            </div>
          
        </asp:Panel>
       
       
        
       
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"       
            BackgroundCssClass="modalBackground"
            Enabled="True"
            TargetControlID="bt1"
            PopupControlID = "PopupPanel"
            OkControlID = "bt_close"
            CancelControlID = "btnCancel"
            DropShadow="true"
             BehaviorID="Panel1"      
            >
        </cc1:ModalPopupExtender>
       
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAgree" />
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel>
       
        </div>
        </form>
    </body>



    结果按下OK后页面可以局部刷新了,但那个 Panel  不消失了
    2010年3月8日 9:33

  •     <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">

        <ContentTemplate>

        <div style="height: 37px">

        <asp:Button ID="bt1" runat="server" Text="1" />

        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>

        <asp:Button ID="bt2" runat="server" Text="2" />

        </div>

            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">

         

            <div class="modalPopup"><br /><br /><br />

                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>

                <br /><br/>

                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" OnClientClick="show()" onclick="AgreePano"

                  />
                  <script language="javascript" type="text/javascript">

                      function show() {
                          var p = $find('Panel1');
                          p.hide();
                      }
                  </script>

                    <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />

                   

                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />

                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />

            </div>

          

        </asp:Panel>

       

       

        

       

     
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"       
            BackgroundCssClass="modalBackground"
            Enabled="True"
            TargetControlID="bt1"
            PopupControlID = "PopupPanel"
            OkControlID = "bt_close"
            CancelControlID = "btnCancel"
            DropShadow="true"
             BehaviorID="Panel1"      
            >
        </cc1:ModalPopupExtender>
       
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAgree" />
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>

        </asp:UpdatePanel>

    • 已标记为答案 scate233 2010年3月11日 8:18
    2010年3月8日 10:04
  • 现在的aspx文件,点击OK后那个panel向上移动了一些,但依旧不消失

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head runat="server">
        <title></title>
        <style type="text/css">
           .modalBackground     
        {
            background-color:#ccc;    
            filter:alpha(opacity=60);    
            opacity:0.6;
        }
        .modalPopup 
        {    
            background-color:#ffffdd;    
            border-width:3px;    
            border-style:solid;    
            border-color:Gray;    
            padding:3px;    
            width:350px;
            height:200px;
        } 
     .noshow
     {
     	display:none;
     }     
        </style>
    </head>
    <body>
       
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div>
        
        <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        <div style="height: 37px">
        <asp:Button ID="bt1" runat="server" Text="1" />
        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>
        <asp:Button ID="bt2" runat="server" Text="2" />
        </div>
            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">
          
            <div class="modalPopup"><br /><br /><br />
                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>
                <br /><br/>
                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" OnClientClick="show()"  onclick="AgreePano" 
                  />
                    <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />
                    
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />
            </div>
           
        </asp:Panel>
        
        
         
        
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"        
            BackgroundCssClass="modalBackground"
            Enabled="True" 
            TargetControlID="bt1"
            PopupControlID = "PopupPanel"
            OkControlID = "bt_close"
            CancelControlID = "btnCancel"
            DropShadow="true" 
             BehaviorID="PopupPanel"       
            >
        </cc1:ModalPopupExtender>
        
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnAgree" />
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel>
        
        </div>
        </form>
         <script language="javascript" type="text/javascript">
    
                      function show() {
                          var p = $find('PopupPanel');
                          p.hide();
                      }
                  </script>
    
    
    </body>
    </html>
    
    
    2010年3月9日 1:14
  • 没有问题啊
    2010年3月9日 3:27
  • 我这边测试没有发现你说的这个情况,很正常阿。
    <%@ Page Language="C#"%>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void AgreePano(object sender, EventArgs e)
        {
            try
    
            {
                tx1.Text = txt_newpano.Text;
            }
    
            catch (Exception err)
    
            {           
    
            }      
    
        }
    
    
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    
    
    <head id="Head1" runat="server">
    
        <title></title>
    
        <style type="text/css">
    
           .modalBackground     
    
        {
    
            background-color:#ccc;    
    
            filter:alpha(opacity=60);    
    
            opacity:0.6;
    
        }
    
        .modalPopup 
    
        {    
    
            background-color:#ffffdd;    
    
            border-width:3px;    
    
            border-style:solid;    
    
            border-color:Gray;    
    
            padding:3px;    
    
            width:350px;
    
            height:200px;
    
        } 
    
     .noshow
    
     {
    
     	display:none;
    
     }     
    
        </style>
    
    </head>
    
    <body>
    
       
    
        <form id="form1" runat="server">
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
    
        </asp:ScriptManager>
    
        <div>
    
        
    
        <asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
    
        <ContentTemplate>
    
        <div style="height: 37px">
    
        <asp:Button ID="bt1" runat="server" Text="1" />
    
        <asp:TextBox ID="tx1" runat ="server" Width="60px"></asp:TextBox>
    
        <asp:Button ID="bt2" runat="server" Text="2" />
    
        </div>
    
            <asp:Panel ID="PopupPanel" runat="server" HorizontalAlign="Center" Style="display: none">
            <div class="modalPopup"><br /><br /><br />
    
                Set Pano:<asp:TextBox ID="txt_newpano" runat="server"></asp:TextBox>
    
                <br /><br/>
    
                <asp:Button ID="btnAgree" runat="server" Text="OK" Width="60px" onclick="AgreePano" />
                <asp:Button ID="Button1" runat="server" CssClass="noshow"  Text="1" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" /><br />
                <asp:Button ID="bt_close" runat="server" CssClass="noshow"  />
    
            </div>
    
           
    
        </asp:Panel>
    
        
    
        
    
         
    
        
    
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"        
    
            BackgroundCssClass="modalBackground"
    
            Enabled="True" 
    
            TargetControlID="bt1"
    
            PopupControlID = "PopupPanel"
    
            OkControlID = "bt_close"
    
            CancelControlID = "btnCancel"
    
            DropShadow="true" 
    
             BehaviorID="Panel1"       
    
            >
    
        </cc1:ModalPopupExtender>
    
        
    
        </ContentTemplate>
    
        </asp:UpdatePanel>
    
        
    
        </div>
    
        </form>
    
    </body>
    
    </html>

    Microsoft Online Community Support
    2010年3月9日 3:52
  • 有问题,楼上你的代码运行起来还是会整页刷新,我要的是局部刷新

    2010年3月9日 4:47
  • 没有问题啊

    你那里运行我贴出来的那段代码,那个土黄色panel按了ok后会消失吗?我这里还是显示在上面啊
    2010年3月9日 4:49
  • 没有问题啊

    你那里运行我贴出来的那段代码,那个土黄色panel按了ok后会消失吗?我这里还是显示在上面啊
    你的代码正常啊
    2010年3月9日 7:07
  • 看来是我的项目出问题了,那个土黄框应该是在按了ok之后不显示的,可我这里按了它还在
    2010年3月9日 7:56
  • 不用这个控件了,改用回传统的CSS+div的遮罩方式算了

    2010年3月11日 7:25