我有一个像这样的事件的复选框:
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);
是否可以在不创建函数的情况下从服务器端调用事件?
答案 0 :(得分:1)
如果您只想调用您的方法,您喜欢这个:
cbRating1WithoutExceptionP1_CheckedChanged(null, EventArgs.Empty);