2017-08-25 33 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 
     } 

    }