我正在创建一个警报并尝试在按下警报的“确定”时通过 javascript 函数调用一个单击事件。如果我在 rpage_Load 上创建警报但是当我在单击按钮时创建警报时它运行得很好,然后按下未调用警报所需的单击事件的“确定”。
这就是我创建警报的方式
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Startup", "Test();", true);
}
这是调用点击事件的javascript函数
<script type="text/javascript">
function Test() {
alert('There is no Bookmarked Question Available');
document.getElementById('btnReview').click();
}
</script>
这是将通过 Test() 调用的点击事件
protected void btnReview_Click(object sender, EventArgs e)
{
count = int.Parse((string)ViewState["S.NO"]);
dt1 = (DataTable)ViewState["Question"];
if (rbOption.SelectedValue != "")
{
string strUserOpt = rbOption.SelectedItem.Text;
strUserOpt = strUserOpt.Substring(20);
dt1.Rows[count - 1][9] = strUserOpt;
dt1.Rows[count - 1][10] = rbOption.SelectedValue;
}
lblReview.Visible = true;
tblQues.Visible = false;
tblReview.Visible = true;
btnBookMark.Text = "Bookmark";
btnBookMark.Font.Bold = false;
btnBookMark.BackColor = Color.Empty;
lblQuestionNo.Visible = false;
lblTopic.Visible = false;
lblTestHead.Visible = false;
DataTable dt = new DataTable();
dt.Columns.Add("Question");
dt.Columns.Add("Status");
dt.Columns.Add("BookMarked");
DataRow dr1;
foreach (DataRow dr in dt1.Rows)
{
dr1 = dt.NewRow();
dr1[0] = dr[0].ToString() ;
if (dr[9].ToString() != "") { dr1[1] = "Attempted"; } else { dr1[1] = "Un-attempted"; }
if (dr[11].ToString() != "") { dr1[2] = "Yes"; } else { dr1[2] = "No"; }
dt.Rows.Add(dr1);
}
dt.AcceptChanges();
ClsDataBind.DoGridViewBind(grdReview, dt, _errMsg);
btnBookMark.Visible = false;
btnNext.Visible = false;
btnPrevious.Visible = false;
btnReview.Visible = false;
}