A页面ShowDialog B页面,B页面关闭时,怎么把一个变量给A页面

解决方案 »

  1.   

    在A页面里,设置一个Public的控件和变量,在B页面里给这些变量赋值,都不行。
      

  2.   

    function Pop() 
        {
           var result=showModalDialog('../customers/customer_select.aspx?facid=<%=factid %>','customerpage','dialogWidth:500px;dialogHeight:400px;center:yes;help:no;resizable:no;status:no');  //打开模态子窗体,并获取返回值
           //window.open('../_popup/customer_select.aspx');
           if (result != undefined)
           {
           document.getElementById("hid_customercode_2").value=result.split("^")[0];  //返回值分别赋值给相关文本框
           document.getElementById("tb_customername_2").value=result.split("^")[1];
           }
        } function select(code,name,address,tel,fax,postcode)
         { 
             window.returnValue= code + "^" + name + "^" + address + "^" + tel + "^" + fax + "^" + postcode;   //返回值    
             window.close(); 
         }ondblclick="javascript:select('<%# Eval("customercode") %>','<%# Eval("customername") %>','<%# Eval("address") %>','<%# Eval("tel") %>','<%# Eval("fax") %>','<%# Eval("postcode") %>');"
      

  3.   

    楼上是asp.net的吧....直接将你要的变量封装成一个对象
    传到B页面
    就可以了 
      

  4.   


    A页面:
    MyArg temp = new MyArg();
    B b = new B(temp);
    b.ShowDialog();
      

  5.   


    你在B 中修改 temp 返回A时  值也改变了楼主没有分清楚值传递和地址传递
      

  6.   

    A页面设置个public变量,B往A的变量赋值
      

  7.   

    也可以用 ref    和 out int i;
    B b = NEW B(ref i);
    b.showDialog();
      

  8.   

    B面可以设置一个public变量int i;
    B b = NEW B();
    b.showDialog(); i = b.i;
      

  9.   

    参见
    http://dotnet.aspx.cc/article/00000000-0000-0000-0000-00000000000f/read.aspx
      

  10.   

    public A()
    {
    B b = new B();b.FormClosing+=new FormClosingEventHandler(B_FormClosing);
    }
    private void B_FormClosing(object sender, EventArgs e)
    {
     Form b = sender as Form;
     b.变量=。。
    }
      

  11.   

    方法挺多的
    方法1:用static变量配合返回状态方式class C { static string c; }
    class B
    {
        private void btnOk_Click(...)
        {
            C.c = "来自B";
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
    class A
    {
        private void ss()
        {
            B b = new B();
            if (b.ShowDialog() == DialogResult.OK) MessageBox.Show(C.c);
        }
    }
    方法2:用委托class A
    {
        private void aa(string a)
        {
            MessageBox.Show(a);
        }    private void ss()
        {
            B b = new B(aa);
            b.ShowDialog();
        }
    }
    class B
    {
        public delegate void BB(string b);
        private BB _bb;    public B(BB bb) { _bb = bb; }    private void btnOk_Click(...)
        {
            this.Close();
            if (_bb != null) _bb("来自B");
        }
    }
      

  12.   

    asp.net的东西?如果是,net4.0本身具备此功能,自己好好找找帮助。
      

  13.   

        public partial class B : Form
        {
            public B()
            {
                InitializeComponent();
            }
            public delegate void MyDelegate(string str);
            public event MyDelegate mydelegate;
            private void button1_Click(object sender, EventArgs e)
            {
                if (mydelegate != null)
                    mydelegate("this is B");
                this.Close();
            }
        }    public partial class A : Form
        {
            public A()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                B b = new B();
                b.mydelegate += TestDelegate;
                b.Show();
            }
            public void TestDelegate(string str)
            {
                label1.Text = str;
            }
        }
      

  14.   

    搞那么复杂干吗 就A页面定义    static public string bl = "";A页面 调用B 按钮代码如下              XzmxForm xzmx = new XzmxForm();  //实例化B页面
                    xzmx.htbh = htbh.Text.ToString();
                    DialogResult dr = xzmx.ShowDialog();
                    if (dr == DialogResult.OK)
                    {                 }
       B页面操作完 后
                        A.bl = ""; //这里你要B到A的值                    this.DialogResult = DialogResult.OK;