Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call javascript function from vb.net code?

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?

like image 953
Novus Avatar asked Jan 20 '14 05:01

Novus


People also ask

Can I use javascript in VB net?

In reality, you don't need to embed any javascript into your vb.net code. Simply include a javascript file into your page and use the jQuery's . on() event handler.

How can call javascript function from server side in ASP NET?

The JavaScript Client Side function will be called from Code Behind (Server Side) using ClientScript RegisterStartupScript method. The following HTML Markup consists of an ASP.Net Button and a Label control. The following JavaScript Client Side function will be called from Code Behind (Server Side) in ASP.Net.


1 Answers

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.

like image 171
Aaron Palmer Avatar answered Sep 30 '22 23:09

Aaron Palmer