在客户端,我用一段js代码从子窗口向父窗口传值,用客户端按钮激发该js代码,而点击此按钮时还需要调服务器端的保存事件,请问我该咋办啊?
js代码:
function Done()
{
var ParmA =document.all.<%=TextBox1.ClientID%>.value;

var MyArgs = new Array(ParmA);

window.returnValue = MyArgs;
window.close();
}
服务器端保存事件:
private void InsertData()
{
   ……………………
}

解决方案 »

  1.   

    是想在服务器端获得TextBox1里的值进行保存操作?
    可以这样吗?触发Done()事件的按钮为 Button 这样在服务器端些一个Button1_Onclick事件不可以吗?应该可以的.执行完客户端后回去执行服务器端的事件的.
    Button1.Attributes.Add("onclick","Done()");
    我试试.
      

  2.   

    楼主参考这个,我测试过了.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>father</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <script>
    function aaa()
    { var svalue = showModalDialog("child.aspx","","dialogWidth:300px;dialogHeight:300px");
    document.getElementById("aa").value = svalue;
    }
    </script>
    </SCRIPT>
    </HEAD>
    <body MS_POSITIONING="FlowLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体"></FONT><input type="text" id="aa" name="aa"> <input type="button" value="ok" onclick="aaa();">
    </form>
    </body>
    </HTML>
    --------------------------------
    <%@ Page language="c#" Codebehind="child.aspx.cs" AutoEventWireup="false" Inherits="aspnetc.test.child" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>child</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <base target="_self">
    </HEAD>
    <body MS_POSITIONING="FlowLayout">
    <form id="Form1" method="post" runat="server">
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
    <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
    </form>
    </body>
    </HTML>
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace aspnetc.test
    {
    /// <summary>
    /// child 的摘要说明。
    /// </summary>
    public class child : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string aaa = TextBox1.Text;
    //进行数据保存操作.
    //............
    string str ="<script>\n";
    str +="var ParmA ='"+TextBox1.Text+"';";
    str +="window.returnValue = ParmA;\n";
    str +="alert(ParmA);\n";
    str +="window.close();\n";
    str += "</script>";
    Response.Write(str);

    }
    }
    }
      

  3.   

    把你的“从数据库里读数据填到页面”的相关代码放到Done()里面,用<%%>括起来
      

  4.   

    思路:
    在打开的窗口中,为确认按钮(服务器端控件)添加Button1_Click事件,先进行数据的保存操作;
    保存操作之后把一段js代码输出.这段JS代码的功能就是Done的功能,惟独不同的是这段JS代码是直接运行,而不是写在function 中.
    需要注意的是在打开的窗口中<head>之间加入<base target="_self">.它用来控提交服务器的时候在本页打开,而不是新的窗口中打开.
               <HEAD>
                .......
    <base target="_self">
             ............
    </HEAD>
    -------------------------------------------------------
    我原来的思路现在看来好象有问题,原来的思路好象时候JS有返回值的function,返回ture的时候执行完客户端后再执行服务器端,但这里......