0

I know you can do this with the following

ClientScript.RegisterStartupScript

But is there a cleaner way to do this. I heard this is a messy way of calling jscript functions and i should never do it. Is this true?

3
  • Do you have any specific scenario ? Commented Nov 21, 2011 at 11:57
  • Hi, On a button click inside an update panel. Run a block of code and then call the javascript function Commented Nov 21, 2011 at 12:02
  • i have a cleaner way but it depends on you code , i mean if you wont to run your javascript after a specific server button click it also depends on where is the button if its on update panel you can attach add_beginRequest and add_endRequest event to the update panel through the pageLoad method to handel if a specific button click on the end request do something on the other hand if your button is clean with out update panel you should use window.onload event and catch the cause post back element from there if you need a complete scenario i can give you one if that's what you want Commented Nov 21, 2011 at 12:32

2 Answers 2

2

ClientScript.RegisterStartupScript is the clean way of doing this.

I think that outputting javascript directly to the page (Response.Write) or onto a Literal control is messier.

Sign up to request clarification or add additional context in comments.

Comments

0

I am not fully aware about what the best practice is. But in my case I use jGrowl to notify the user whether an action either succeded or failed, i.e.:

ScriptManager.RegisterClientScriptBlock(this.Page,
    typeof(Page), Guid.NewGuid().ToString(),
    "$.jGrowl('The Group was successfully created, { theme: 'succeeded'});", true);

Hope this helps!

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.