How do I execute javascript from code behind in aspx

I have a javascript function in my aspx page
    <script type="text/javascript" language="javascript">

        function showDialogue() {alert ("It worked"); }
    </script>

And I have this in my code behind at the form load
Page.ClientScript.RegisterStartupScript(Page.GetType(), "Key", "showDialogue", True)

A response.write proves to me that the form load is being run, but the alert doesn't show

What am I doing wrong?
LVL 4
g_johnsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Not fully conversant with .net but calling functions in js requires () when used i.e.

Page.ClientScript.RegisterStartupScript(Page.GetType(), "Key", "showDialogue()", True)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Gary's got your answer. I'll expand on why  = )

The RegisterStartupScript method's third argument is the actual script code you want to run. You could just as easily put your alert code in that parameter. Since you instead put the script code in your .aspx page, you simply need to pass a call to that function--what Gary mentioned--as your script. Adding the parens (and probably a semi-colon for good measure) should cause it to execute.
0
g_johnsonAuthor Commented:
kaufmed --

that's interesting.  This was just a small test for what will be a much more complex function:

        function CS15922_SysPrintSelect(division, page, onchangeScript, ctl_no, item_no, qty)
 {

            icsysDivision = division;

            var args;
            var u = "CS15922_PrintSelect.aspx?Division=" + icsysDivision + "&Id=" + id + "&@endnum=" + qty + "&bpEM=" + byrPlnrEmail + "&updateNumber=1";

            SysDialog.ctl = null;
            SysDialog.bKeyInRef = null;
            SysDialog.refurl = page;
            SysDialog.onchangeScript = onchangeScript;
            SysDialog.extraResults = "";
            SysShowModal(u, args, "850px", "600px", "CS15922_SysPrintSelectHandler();", true);

        }

Am I understanding you to say that I could put each of the commands in the function into the third parameter of the RegisterStartupScript separated by semicolons and it would run just fine?

Due to the complexity I believe I'll leave it as a function, but I just wanted to be sure I understand.

Thanks to both of you!
0
käµfm³d 👽Commented:
In theory, yes that should work. I'm only going by what the docs say. I haven't really used RegisterStartupScript. I usually stuff everything into the .aspx (well, .cshtml file now, since almost all of our work is in MVC). For things to run at startup, we usually use JQuery.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.