# VBForums CodeBank > CodeBank - ASP / ASP.NET / MVC / Web API >  Dynamic Alert/MessageBox

## RobDog888

Run this code from any code behind event to invoke a alert/msgbox without having to use Page.RegisterStartupScript() or using an objects .Attributes property to tie an js alert to it.

This is independant from any object and just like having a VB6/VB.NET Messagebox.


VB Code:
Protected Sub SomeSub(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Write("<script language=javascript>alert('This is a dynamic alert.');</script>") '
End Sub

----------


## mendhak

Edit

Dude, not a good idea.

Response.Write is not a good thing to use on ASP.NET pages.

----------


## RobDog888

Then how would you recomend invoking a alert without having to use a hidden control or something?

Say if you wanted to evaluate a couple of aspx controls and depending on the scenerio, call a message?

----------


## Fishcake

> Then how would you recomend invoking a alert without having to use a hidden control or something?
> 
> Say if you wanted to evaluate a couple of aspx controls and depending on the scenerio, call a message?


By using Page.RegisterStartupScript.

----------


## RobDog888

Yes, I learned that one a while ago as it was a question froggy couldnt answer when I was just starting to learn asp.net.  :Big Grin:

----------


## freefall

> Edit
> 
> Dude, not a good idea.
> 
> Response.Write is not a good thing to use on ASP.NET pages.


then what else do u use to display anything on the page from the code-behind?

----------


## RobDog888

Hes means to use other methods like - Me.Page.RegisterStartupScript(...

or ...

Me.Page.RegisterClientScriptBlock(...

----------


## freefall

ahh ok, so for registering javascripts...

not exactly just trying to display Hello, World! on the page..

Cool, thanks for clearing that up

----------


## RobDog888

VB Code:
Me.Page.RegisterStartupScript("script1", "<script language='JavaScript' type='text/javascript'>alert('Hello World');</script>")
No need for js in the html.  :Smilie:

----------

