0

I have a button in my updatepanel and I'm trying to call a javascript function (after it does it's processing).

I put this code inside the 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 + "');")

Client Side javascript:

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

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

How do I pass the values I gather from the server side click event into the javascript function?

2
  • you have it tagged as C# when in-fact it's VB have you tried a simple google search in regards to invoking Javascript using jquery Commented Mar 2, 2015 at 23:02
  • @MethodMan - sorry about that I corrected it. I have and I'm currently looking at populating a hiddenfield but I'm not liking that solution right now either. Commented Mar 2, 2015 at 23:09

1 Answer 1

1

I suppose your question is about . In this case try this in the 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" />

And this in the CodeBehind

Private Sub postButton_Click(sender As Object, e As EventArgs) Handles postButton.Click
    YourLogic(hiddenField.Value)
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

yes I have a solution similar to that. However, I need the postButton to populate the data first and then open the modal window (all in 1 step). What I'm seeing with my implementation is that I click the asp.net button the modal opens with no data until I close the window and open it again.
You can just add your function before the asp on click. I'll update the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.