0

I am trying to load jQuery dialog from code behind gridview rowcommand. Looks like javascript function is not firing from code behind.

.vb file

Private Sub grdLoan_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grdLoan.RowCommand
  If e.CommandName = "pdf" Then

    Dim message As String = "This is test message"
    ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "ShowPopup('" + message + "');", True)
    'ScriptManager.RegisterClientScriptBlock(grdLoan, Me.[GetType](), "MyScript", "ShowPopup('" + message + "');", True)
   End If
End Sub

if I use alert in clientscript it is working fine. but JS function not working.

 ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "alert("This is test message"", True)

html

<div id="dialog" style="display: none">
</div>
 <script type="text/javascript">
         function ShowPopup(message) {
            alert(message);
                $(function () {
                    $("#dialog").html(message);
                    $("#dialog").dialog({
                        title: "jQuery Dialog Popup",
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                            }
                        },
                        modal: true
                    });
                });           
        };
 </script>

1 Answer 1

1

Yes it was not working, I made some modifications and now its working at my end. If you have a scriptmanager on your page, you can try this:

 string message = "This is test message";
                string jqueryCodeString = @"<script type='text/javascript'>ShowPopup('" + message + "');</script>";
                ScriptManager.RegisterStartupScript(this, typeof(string), "Confirm1", jqueryCodeString, false);
Sign up to request clarification or add additional context in comments.

Comments

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.