熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET 窗體間傳值的方法

2013-11-13 10:40:19  來源: .NET編程 
這篇文章介紹了ASPNET 窗體間傳值的方法有需要的朋友可以參考一下希望對你有所幫助  

  假設ParentFormaspx 頁面上有TextBox文本框和Open按鈕
點擊Open按鈕彈出SubFormaspxSubFormaspx頁面上有TextBox文本框和Close按鈕
點擊Close按鈕關閉SubFormaspx頁面並把子頁面SubFormaspx文本框的值顯示到父頁面ParentFormaspx 的文本框上
父窗體前台代碼

復制代碼 代碼如下:
      <script type="text/javascript">
        function OpenSubForm(ret) {
            var strPath = "subFormaspx"
            var nHeight =
            var nWidth =
            var feature
            feature = "Height= " + nHeight + "Width=" + nWidth + "top=Left=";
            feature += "dependent=yeslocation=noresizable=yesscrollbars=yesstatus=yestoolbar=no;";
            windowopen(strPath+"?Ret_Form=Form&Ret_Value="+retsubFormfeature)focus();
            return false;
        }
    </script>

  
父窗體後台代碼

復制代碼 代碼如下:
private void Page_Load(object sender SystemEventArgs e)
        {
            // ページを初期化するユーザー コードをここに挿入します
            thisButtonAttributesAdd("onClick""return OpenSubForm(TextBox);");
        }

  
子窗體後台代碼

復制代碼 代碼如下:

  
        private void Button_Click(object sender SystemEventArgs e)
        {
            string strScript =stringEmpty;
            string strRetForm = StringEmpty;
            string strRetValue=StringEmpty;
            strRetForm=RequestParams["Ret_Form"];
            strRetValue=RequestParams["Ret_Value"];
            if (strRetForm == stringEmpty)
            {
                strRetForm= "documentforms[]";
            }
            strScript = "<script language=javascript>";
            strScript += "windowopener" + strRetForm;
            strScript += "" + strRetValue + "value=" + thisTextBoxTextTrim() + ";";
            strScript += "windowclose();";
            strScript += "</script>";
            ResponseWrite(strScript);
        }


From:http://tw.wingwit.com/Article/program/net/201311/14265.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.