0

I'm trying to fire a Jquery function form my C#.NET server side code. basically what im trying is to show a notification. Im using Bootstrap and I have loaded my scripts in the master page. Also I have added my Form and ScriptManager tags in master page. I have a function written in my inner Page Document.Ready. now im trying to call that function from my server side code.

Server Side Code-

  ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showAlertMessages", "showSuccessMessage('Your Password Changed Successfully.');", true);

Client Side function -

<script type="text/javascript">
$(document).ready(function () {

    function showSuccessMessage(message) {
        alert(message);
    }
});
</script>

But when I do this, It gives me the

Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I have tried turning off the event validation, then the error does not come but the function is not getting called.

Any thoughts ?

Simon Karlsson
  • 4,090
  • 22
  • 39
Kasun Koswattha
  • 2,302
  • 2
  • 12
  • 20

1 Answers1

0

Try using String.Format like this:

const string message = "Your Password Changed Successfully.";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showAlertMessages", String.Format("showSuccessMessage('{0}');", message), true);
terbubbs
  • 1,512
  • 2
  • 25
  • 48