如何将代码隐藏信息传递给javascript函数

时间:2015-03-02 22:53:13

标签: javascript jquery asp.net vb.net

我的更新面板中有一个按钮,我试图调用javascript函数(在它处理完之后)。

我将此代码放在Page_Load

    Dim cstype As Type = Me.GetType()
    Dim cs As ClientScriptManager = Page.ClientScript
    cs.RegisterStartupScript(cstype, "modalScript", "jsModal('" + msg + "');", True)
    keywordSearch.Attributes.Add("onclick", "jsModal('" + msg + "');")

客户端javascript:

function showModal(msg) {
    $("#modal-content, #modal-background, #modal-close").toggleClass("active");
    var returnString = msg;

    $('#modal-content div').each(function (index) {
        $(this).html(returnString);
    });
}

如何将我从服务器端点击事件收集的值传递到javascript函数?

1 个答案:

答案 0 :(得分:1)

我想你的问题是。在这种情况下,请在aspx

中尝试此操作
<script type="text/javascript">
    $(document).ready(function() {
        $("#buttonTest").click(function () {
            $("#<%= hiddenField.ClientID%>").val("TEST");
        });
    });
</script>
<asp:HiddenField runat="server" ID="hiddenField" />
<button id="buttonTest">
    Change value hidden field
</button>
<asp:Button runat="server" Text="POST" ID="postButton" />

这在CodeBehind

Private Sub postButton_Click(sender As Object, e As EventArgs) Handles postButton.Click
    YourLogic(hiddenField.Value)
End Sub