现有两个页面,父页面为Default.aspx,子页面为child.aspx。父页面的设计代码如下:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %><!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>
    <script type="text/javascript" >
    function showDialog()
    {
        window.showModalDialog("child.aspx",null,"status=no;dialogWidth=200px;dialogHeight=250px;menu=no;"
                    +"resizeable=no;scroll=yes;center=yes;edge=raise");
    }
    </script >
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TextBox ID="noChangeTextBox" runat="server">这里面的内容不需要刷新</asp:TextBox>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="changeTextBox" runat="server" Height="108px" Width="249px">点击子窗体按钮时,只需要更新此文本框</asp:TextBox>
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <asp:Button ID="refButton" runat="server" Text="显示子窗体" /></div>
    </form>
</body>
</html>在后台的Default.aspx的Page_Load代码如下:
protected void Page_Load(object sender, EventArgs e)
    {
        refButton.Attributes.Add("onclick", "return showDialog();");//显示“添加批前规划公示”对话框
    }子窗体child.aspx的页面代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="child.aspx.cs" Inherits="child" %><!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">
    <base target="_self"/>
    <title>子窗体页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Height="32px" Text="对父窗体局部刷新的操作" Width="177px" /></div>
    </form>
</body>
</html>

现在当我点击子页面child.aspx的Button1按钮时,如何只刷新父页面Default.aspx的changeTextBox文本框内容,而页面其它部分的内容不被刷新
。谢谢

解决方案 »

  1.   

    把父窗体对像传过去,直接在子窗体中给他赋值即可。
    window.showModalDialog("child.aspx",父窗体上的对象,"status=no;dialogWidth=200px;dialogHeight=250px;menu=no;" 
                        +"resizeable=no;scroll=yes;center=yes;edge=raise");
      

  2.   

    function showDialog() 
        { 
          var returnvalue= window.showModalDialog("b.aspx",null,"status=no;dialogWidth=200px;dialogHeight=250px;menu=no;" 
                        +"resizeable=no;scroll=yes;center=yes;edge=raise"); 
                      if(returnvalue !=null)
                      {
                        document .getElementById ("changeTextBox").value=returnvalue ;
                        }
        } 
    child页面
      <form id="form1" runat="server"> 
        <div> 
        <script>
         function Returns(){ 
           var name = document .getElementById ("revalue").value;
           window.returnValue=name;//窗体返回值 
          alert (name);
           window.close(); 
        } 
        </script>
        输入要改的值:<asp:TextBox runat=server ID=revalue ></asp:TextBox>
         
          
         <asp:Button ID="Button1" runat="server" Height="32px" Text="对父窗体局部刷新的操作" Width="177px"  OnClientClick ="Returns()" /> 
          </div>
      

  3.   

    还有一种
    function showDialog() 
        { 
           window.open("b.aspx",null,"status=no;dialogWidth=200px;dialogHeight=250px;menu=no;" 
                        +"resizeable=no;scroll=yes;center=yes;edge=raise"); 
                    
        } function Returns(){ 
           var name = document .getElementById ("revalue").value;
          window .opener .document.all.changeTextBox.value=name;//最好是只有一个(id唯一)
          window .close ();
        } 
      

  4.   

    Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!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 id="Head1" runat="server"> 
        <title>父窗体页 </title>  
       <script type="text/javascript" src ="JScript.js"></script> 
     </head> 
    <body> 
        <form id="form1" runat="server"> 
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server"> 
            </asp:ScriptManager> 
            <asp:TextBox ID="noChangeTextBox" runat="server">这里面的内容不需要刷新 </asp:TextBox> 
            <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
                <ContentTemplate> 
                    <asp:TextBox ID="changeTextBox" runat="server" Height="108px" Width="249px">点击子窗体按钮时,只需要更新此文本框 </asp:TextBox> 
                </ContentTemplate> 
            </asp:UpdatePanel> 
            <br /> 
            <asp:Button ID="refButton" runat="server" Text="显示子窗体" /> </div> 
        </form> 
    </body> 
    </html> Jscript.js
    function showDialog() 

        window.showModalDialog("child.aspx",window,"status=no;dialogWidth=200px;dialogHeight=250px;menu=no;" 
                    +"resizeable=no;scroll=yes;center=yes;edge=raise"); // 把父窗口当作参数传给子窗口
    } function ChangeText(Text)
    {
        document.getElementById('changeTextBox').value=Text;
    }Default.aspx.cs
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            refButton.Attributes.Add("onclick", "return showDialog();");//显示“添加批前规划公示”对话框 
        }
    }
    child.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="child.aspx.cs" Inherits="child" %><!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 id="Head1" runat="server"> 
        <base target="_self"/> 
        <title>子窗体页 </title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <div> 
            <asp:Button ID="Button1" runat="server" Height="32px" Text="对父窗体局部刷新的操作" 
                Width="177px" onclick="Button1_Click" /> </div> 
        </form> 
    </body> 
    </html> 
    child.aspx.cs
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class child : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }    protected void Button1_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(this.GetType(), String.Empty, "<script>window.dialogArguments.ChangeText('aaa');</script>"); // 传进来的参数window.dialogArguments是父窗口,所以就是调用父窗口的js函数ChangeText
        }
    }