无法通过警报调用javascript函数

时间:2013-11-08 05:34:41

标签: c# asp.net alert javascript

我正在创建一个警报并尝试在按下“确定”警报时通过javascript函数调用click事件。如果我在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()

调用的click事件
 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;

    }

1 个答案:

答案 0 :(得分:1)

主要问题可能是您在btnReview之后单击Button1因为在btnReview_Click下 发生这种情况

btnReview.Visible = false;

这意味着除非

,否则您将无法使用Button1_Click事件
btnReview.Visible = true;