7

I have written VB.NET code for calling my Javascript function showDisplay().

vb.net code:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "showDisplay();", True)

javascript code:

function showDisplay(){
alert('success');}

but this is not working, can you help?

1

1 Answer 1

15

Perhaps you are looking for RegisterStartupScript:

ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "showDisplay();", True)

Depending on where your showDisplay() javascript function exists in your code, using RegisterClientScriptBlock may not find it. This is because RegisterClientScriptBlock places the javascript at the top of your page, immediately after the viewstate. Using RegisterStartupScript will place the call to showDisplay() at the very bottom of your form, so it will be rendered last and your javascript function will have already been rendered and available.

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

3 Comments

if showdisplay message have arguments how to send it?
Depends. Does the server side have knowledge of the argument values? If so, put them inline showDisplay(\"StringValue1\", \"StringValue2\"). Are the values only available on the browser? If so, provide variable names and ensure that the JavaScript contains these variables prior to calling showDisplay(var1, var2).
What if I have my JavaScript function wrote down under a different file?

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.