0

Afternoon,

I have been able to call JavaScript functions from my C# before and it worked fine. For some reason this time the function is not getting hit when i breakpoint the code.

So this is my C# method.

    public void tester()
    {
        string returnResult = HttpContext.Current.Session["result"].ToString();

        Page.ClientScript.RegisterStartupScript(this.GetType(), "alerify", "alerify('" + returnResult + "');", true);
        //ScriptManager.RegisterStartupScript(this, this.GetType(), "alerify", "alerify(" + returnResult + ");", true);
    }

You can see that i have tried different methods but the function is still not getting hit.

This is the JavaScript function i want to call.

    function alerify(e) {
        alert(e);
        if (e == "InvalidDates") {
            alertify.error("gfgsdggfsdgfsdfd");
        }
    }

I am thinking that i am missing somthing but i just don't know what.

2
  • 3
    Please show your code as a text, not as an image. Commented May 18, 2015 at 12:43
  • @SonerGönül Sorry, i will edit the post with the code. Commented May 18, 2015 at 12:49

1 Answer 1

3

As it's a string value it needs apostrophes (or quotation marks) to be a string literal in the JavaScript code:

... "alerify('" + returnResult + "');" ...
Sign up to request clarification or add additional context in comments.

5 Comments

The problem is still occurring.
@BenClarke: Do you get any error message in the console log?
@BenClarke: Are you sure that the server code actually runs?
Yes, i have debugged the server code and it hits the line.
@BenClarke: What kind of request is running the server code? Does RegisterStartupScript have a chance to put any code in the page?

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.