Call Alert When I Get a Session Value

Asked

Viewed 65 times

0

Hello!

I am trying to call a javascript Alert as soon as I get some value in a Session. I am using C# with ASP.NET

Follow my code with the attempt to show Alert, but to no avail:

@if((string)Session["alertaErro"] != null)
{
    <script>
        function chamalerta() {
            bootbox.alert(@Session["alertaErro"]);
        }

        chamalerta();
    </script>
}
  • Where the alert session value is set?

  • you can try putting a $(Document). ready(Function(){chamalerta();});

  • Jean, Session receives the value when the user tries to access a page that he does not have permission for. But Session has value inside it, I’ve done the tests, I just wanted to display the message as an Alert, because hj I’m displaying the message in a div

  • Bruno, I tried to do the way you said but it returns me some errors and does not go through the block that calls the function, it just identifies that the Session is null and does not go through the script. Errors: Uncaught Syntaxerror: Missing ) after argument list Uncaught Referenceerror: $ is not defined at

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.