2015-02-11 34 views
-1

调用代码我有这样与事件复选框:如何从背后服务器端

protected void cbRating1WithoutExceptionP1_CheckedChanged(object sender, EventArgs e) 
     { 
      if (cbRating1WithoutExceptionP1.Checked == true) 
      { 
       cbRating1WithExceptionP1.Checked = false; 
       cbRating1WithExceptionP1.Enabled = false; 
      } 
      else 
      { 
       cbRating1WithExceptionP1.Enabled = true; 
      } 
     } 

如何调用从服务器端的活动?

foreach (string oWithException in oWithExceptions) 
         { 
          switch (oWithException.Trim()) 
          { 
           case "P1": 
            cbRating2WithExceptionP1.Checked = true; 
cbRating1WithoutExceptionP1_CheckedChanged(new object, new EventArgs); 
            break; 
           case "P2": 
            cbRating2WithExceptionP2.Checked = true; 
            break; 
           case "P3": 
            cbRating2WithExceptionP3.Checked = true; 
            break; 
           case "P4": 
            cbRating2WithExceptionP4.Checked = true; 
            break; 
           case "P5": 
            cbRating2WithExceptionP5.Checked = true; 
            break; 
           case "NOT_ALLOWED": 
            cbRating2WithExceptionNotAllowed.Checked = true; 
            cbRating2WithExceptionP1.Checked = false; 
            cbRating2WithExceptionP1.Enabled = false; 
            cbRating2WithExceptionP2.Checked = false; 
            cbRating2WithExceptionP2.Enabled = false; 
            cbRating2WithExceptionP3.Checked = false; 
            cbRating2WithExceptionP3.Enabled = false; 
            cbRating2WithExceptionP4.Checked = false; 
            cbRating2WithExceptionP4.Enabled = false; 
            cbRating2WithExceptionP5.Checked = false; 
            cbRating2WithExceptionP5.Enabled = false; 
            break; 
          } 
         } 
        } 

像这样:

cbRating1WithoutExceptionP1_CheckedChanged(new object, new EventArgs); 

是不是可以调用从服务器端的事件,而不创建一个函数?

+1

你从服务器side.This事件调用事件的意思是已经在服务器端。 – 2015-02-11 06:30:33

+1

使用这样'cbRating1WithoutExceptionP1_CheckedChanged(空,新EventArgs.Empty);' – 2015-02-11 06:31:49

+6

或拉动相关代码到另一个方法无论是从事件处理程序和您的其他地方 – 2015-02-11 06:35:46

回答

1

你喜欢这个,如果你想只调用您的方法:

cbRating1WithoutExceptionP1_CheckedChanged(null, EventArgs.Empty); 
+0

我的代码,如下所示: cbRating1WithoutExceptionP1_CheckedChanged(NULL,EventArgs.Empty); – Khaneddy2013 2015-02-11 07:42:43

+0

@ irhabymailed4u是的,它应该是我现在纠正了错误 – 2015-02-11 07:46:37