1

我试过

Protected Sub btn_add_question_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_add_question.Click
        frm_course.Visible = False
        question_div.Visible = True
        ScriptManager.RegisterClientScriptBlock(btn_add_question, Me.GetType(), "BlockName", "alert('hello world');", True)
    End Sub

Protected Sub btn_add_question_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_add_question.Click
        frm_course.Visible = False
        question_div.Visible = True
        Page.ClientScript.RegisterStartupScript(Me.GetType, "Javascript", "alert('hello')")
    End Sub

但是,没有显示警报消息。需要帮忙 !!

 <asp:Button ID="btn_add_question" runat="server" Text="Next" CssClass="btn_submit" Width="101px" />
4

2 回答 2

3

您需要将<script>标签True作为最后一个参数传递给函数调用,RegisterStartupScript如下所示:

Page.ClientScript.RegisterStartupScript(Me.GetType, "Javascript", "alert('hello');",True)

更新

试试这个:

ScriptManager.RegisterStartupScript(Me.GetType, "Javascript", "alert('hello');",True)
于 2012-07-24T18:44:15.983 回答
-2

OnClientClick处理程序添加到按钮,或者更好的是,通过 javascript 将处理程序附加到应该在的位置。

<asp:button id="myButton" runat="server" text="Postback" onclientclick="alert('hello world');" />

如果您所做的只是更改某些元素的某些可见性,那么您甚至根本不应该回帖。只需使用input type="button"并通过 javascript 显示/隐藏。

<input type="button" value="Next" id="btn_add_question" />

document.getElementById('btn_add_question').onclick = function () {
    document.getElementById('frm_course').style.visibility = 'hidden';
    document.getElementById('question_div').style.visibility = 'visible';
    alert('hello world');
};
于 2012-07-24T18:40:13.697 回答