2012-01-31 77 views
0

我有一個字符串列表,它是在imagebutton_click方法上生成的。我希望能夠在另一個網頁中使用此列表。在Asp.Net網頁之間發佈數據

我怎麼不知道如何去發佈它在兩頁之間。

下面我有以下代碼:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e) 
     { 

      RadGrid rg = RadGrid1; 
      //Get selected rows 
      GridItemCollection gdc = (GridItemCollection)rg.SelectedItems; 
      foreach (GridItem gi in gdc) 
      { 
       if (gi is GridDataItem) 
       { 

        GridDataItem gdi = (GridDataItem)gi; 

        if (!string.IsNullOrEmpty(gdi["Email"].Text)) 
        { 

         string client = gdi["Email"].Text; 
         //Creating a List of Clients to be Emailed 
         emailList.Add(email); 

        } 
       } 
         //Enable the Prepare Email Page 
         PageView2.Selected = true; 
      } 


protected void ImageButton2_Click(object sender, ImageClickEventArgs e) 
     { 

      if (emailList.Count != 0) 
      { 
       for (int i = 0; i < emailList.Count; i++) 
       { 
        _to = emailList[i].ToString() + ";"; 

       } 

      } 
      else 
      { 
       _to = emailList[1].ToString(); 

      } 


      //Processing Client Email 
      string _from = sec.GetCurrentUserEmail("test"); 
      string _cc = ""; 
      string _subject = SubjectTB.Text; 
      string _body = EmailEditor.Content; 
      string _tempTo = sec.GetCurrentUserEmail("temp"); 
      string _msg = sec.SendMail(_tempTo, _cc, _from, _subject, _body, ""); 

      if (_msg == "success") 
      { 
       //Thank the user and record mail was delivered sucessfully 
       TestPanel.Visible = true; 

      } 

     } 

我如何獲得的emailList的值通過傳遞給ImageButton2_click(對象發件人,ImageClickEventArgs E)。目前它只是通過一個空值。我收集我需要使用HTML表單來完成請求。謝謝。

回答

0

你可以在ASP.Net here中瞭解到關於狀態管理的一個好主意。對於你的情況,如果button1和button2在相同的aspx頁面,Viewstate將是一個好主意。如果他們在不同的頁面中,則使用會話狀態管理。

1

我猜emailList是一個私有變量?你不能將它添加到LoadControlState和SaveControlState中,以便它稍後可用於ImageButton2_Click?

下面是一個例子:http://msdn.microsoft.com/en-us/library/system.web.ui.control.loadcontrolstate%28v=vs.80%29.aspx

另一種可能是隱藏字段,這可能是simplist方式,但並不安全。

+0

是的,它是一個私人的全局變量。我將如何去保存和加載控制狀態。謝謝。 – user1155383 2012-01-31 07:35:22

+0

已添加到答案。讓我知道它是否有效。 – 2012-01-31 11:57:06