I have a ascx file that is a newsletter sign up. I want it so that when a user submits all his information a popup window says thank you. How do I call a javascript from asp.net (using vb) Thank you
> How do I call a javascript from asp.net (using vb) you don't do it directly, since ASP.NET and javascript run in two completely separate places. Basically just output some javascript code which does the popup when you feel the need to show it. You can't literally
call it though.
RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unreadable
This is how I would execute a javascript from asp.net 1. Drag and Drop a Literal Control on your page (aspx) or control (ascx) 2. In your btnDoSomeThing_Clicked event add this [code] string strjscript = "<script language='javascript'>"; strjscript += "popup();";
strjscript += "</script" + ">"; Literal1.Text = strjscript; [\code] good luck
Ok I am getting this error now.. Object reference not set to an instance of an object This is the code I made:
<script language="JavaScript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=200,left = 312,top = 284');");
}
</script>
<script language="VB" runat="server">
Sub btnNewsLetter_Click(sender as Object, e as EventArgs)
If Not tbName.Text = nothing And Not tbEmail.Text = nothing Then
' code to make the email
'show popup to say thank you.
Dim strPopUp as StringBuilder
With strPopUp
.Append("<script language='java")
.Append("script'>")
.Append("popUp(newsletterthanks.htm);")
.Append("</scri")
.Append("pt>")
End With
litPopUp.Text = strPopUp.ToString()
Try
SmtpMail.Send(mailMsg)
Catch ex as Exception
End Try
End If
End Sub 'btnNewsLetter_Click
</script>
And this is all inside a user control. I am guessing that the scripts aren't placed in the right positions. Cheers Charles
Step in your code to find out which object reference is not set. My guess is strPopUp ( in VB, don't you have to create an instance of an object first before accesing its method? for ex: strPopUp = new StringBuilder)
So... if one wanted to call a javascript function onclick ... isn't it possible to do from the form button? In one page done without codebehind, it worked fine. Now that I'm trying it using codebehind, it seems to not work... is this what you're referring to?
Charles_V
Member
370 Points
74 Posts
Calling Javascript
Dec 08, 2003 01:14 AM|LINK
Atrax
All-Star
18705 Points
3733 Posts
Re: Calling Javascript
Dec 08, 2003 01:30 AM|LINK
Jason Brown - MVP, IIS
Charles_V
Member
370 Points
74 Posts
Re: Calling Javascript
Dec 08, 2003 08:05 PM|LINK
VnetBoy
Member
15 Points
3 Posts
Re: Calling Javascript
Dec 08, 2003 09:35 PM|LINK
Charles_V
Member
370 Points
74 Posts
Re: Calling Javascript
Dec 09, 2003 02:53 AM|LINK
<script language="JavaScript"> function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=200,left = 312,top = 284');"); } </script> <script language="VB" runat="server"> Sub btnNewsLetter_Click(sender as Object, e as EventArgs) If Not tbName.Text = nothing And Not tbEmail.Text = nothing Then ' code to make the email 'show popup to say thank you. Dim strPopUp as StringBuilder With strPopUp .Append("<script language='java") .Append("script'>") .Append("popUp(newsletterthanks.htm);") .Append("</scri") .Append("pt>") End With litPopUp.Text = strPopUp.ToString() Try SmtpMail.Send(mailMsg) Catch ex as Exception End Try End If End Sub 'btnNewsLetter_Click </script>And this is all inside a user control. I am guessing that the scripts aren't placed in the right positions. Cheers CharlesVnetBoy
Member
15 Points
3 Posts
Re: Calling Javascript
Dec 09, 2003 07:33 AM|LINK
Charles_V
Member
370 Points
74 Posts
Re: Calling Javascript
Dec 10, 2003 01:33 AM|LINK
fetlock
Member
465 Points
93 Posts
Re: Calling Javascript
Dec 17, 2003 03:33 PM|LINK