2017-08-25 15 views
0

我不知道如何傳遞在同一c#頁面上Page_LoadPage_PrerenderComplete之間的控件。我試圖通過控件(如字符串ID)Page_PrerenderComplete和Page_Load

protected void Page_Load(object sender, EventArgs e) 
    { 
     //Not sure how to get animallist_hf from Page_PrerenderComplete 
     HiddenField animallist_hf = (HiddenField)Page.FindControl("animallist_hf"); 

     //Not sure how to get animallist_hf from Page_PrerenderComplete 
     string animallist_str = Page.FindControl("animallist_str").ToString(); 

     //Not sure how to get stringSeparators from Page_PrerenderComplete 
     string[] stringSeparators = new string[] { "," }; 

     //Not sure how to get animallist_Array from Page_PrerenderComplete  
     string[] animallist_Array; 

     animallist_Array = sanimallist_str.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); 
     string test = (string)"ggggg".ToString(); 

     CheckBoxList animallist = (CheckBoxList)repeater1.Items[1].FindControl("animallist"); 
     foreach (string i in animallist_Array) 
     { 
      foreach (ListItem listItem in animallist.Items) 
      { 

       if (listItem.Text == i) 
       { 
        listItem.Selected = true; 
       } 

      } 
     } 
    } 

    protected void Page_PrerenderComplete(object sender, EventArgs e) 
    { 
     HiddenField animallist_hf = (HiddenField)repeater1.Items[0].FindControl("animallist_hf"); 
     string animallist_str = (string)animallist_hf.Value; 
     string[] stringSeparators = new string[] { "," }; 
     string[] animallist_Array; 

     animallist_Array = animallist_str.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); 
     string test = (string)"ggggg".ToString(); 

     CheckBoxList animallist = (CheckBoxList)repeater1.Items[0].FindControl("animallist"); 
     foreach (string i in animallist_Array) 
     { 
      foreach (ListItem listItem in animallist.Items) 
      { 

       if (listItem.Text == i) 
       { 
        listItem.Selected = true; 
       } 

      } 
     } 

    } 
+0

沒有人會去調試你的代碼你。沒有人會閱讀源代碼評論來找出你想要的東西。試着重新格式化這個問題來問一個具體的問題,並顯示你已經完成了什麼以及你得到了什麼結果。 – jdv

+0

你想要什麼代碼?它究竟在做什麼? – mjwills

+0

也許你可以告訴我們爲什麼你要這樣做,我認爲有一個更好的方法來做到這一點。 – thepanch

回答

0
// declare class variable 
int x; 
protected void Page_Load(object sender, EventArgs e) 
    { 
     // define class variable 
     x = 1; 
    } 

    protected void Page_PrerenderComplete(object sender, EventArgs e) 
    { 
     // use class variable 
     if (x == 1) { 
      // do stuff 
     } 

    } 
相關問題