The most popular response is “
ScriptManager.RegisterStartupScript” however, that does not work in my situation.
So I am doing something like
How do I call this function from my vb.net class?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
If DataStore.Record.Exists(theRecord) Then Dim script As String = "alert('Record exists')" If Not Page.ClientScript.IsStartUpScriptRegistered(Me.GetType(), "alertscript") Then Page.ClientScript.RegisterStartUpScript(Me.GetType(), "alertscript", script, True) End If End If
you would do it like above, where you should replaceDataStore.Record.Exists(theRecord) with condition that checks database record exists
If you were doing a full page postback, a crude way of achieving it would be to assign the script or function to a
Literal control, which renders its
Text property on the HTML page exactly as written.
Then, your script will execute at the point the
Literal is rendered.
A neater way of doing it is to add your script to the page via a
ScriptManager as you noted. Rather than a
StartupScript, you could try using
.RegisterClientScriptBlock() instead? You don’t mention what it is about your situation that doesn’t work?
The most comprehensive way of doing it would be to use AJAX – either .NET’s built-in framework, or jQuery. jQuery’s AJAX (and AJAX in general) is a separate topic, which you can read about here.