VWD 2005 Express. Visual Basic. How may I create a "pop up" window (with it own controls for closing the window) and call it (open it) from the code behind? Thanks for the help.
Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
you should not need to call it from codebehind you just call it from client side javascript.
this is what i use all the time :
function genericPopup(href, width, height, scrollbars){
var param =
"width="+width+", height="+height+", scrollbars="+scrollbars+",
resizable, status";
return window.open(href,
"", param);
}
then i just pass it the href (url), width, height, and if we want scroll bars or not.
to call it from a link you would use
<a href="MyDestinationPage.aspx" onClick="genericPopup(this.href,300,300,no)">Click for popup</a>
if you NEED to call it from serverside you need to inject the javascript into codebehind and use RegisterClientScriptBlock method (which is complicated) if you can avoid doing it from code-behind i would.
Suppose that I want to pass some text content to the WebForm2.aspx file that is opened by your example. How would I pass this text information? What I am trying to do is display a particular message (which will come from a database and hence is not fixed)
in the pop up window. Thanks for your continued help.
Dr. Douglas Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
Chaplain Dou...
Member
305 Points
934 Posts
How to Create and Call a Popup Window
Dec 05, 2007 06:10 PM|LINK
VWD 2005 Express. Visual Basic. How may I create a "pop up" window (with it own controls for closing the window) and call it (open it) from the code behind? Thanks for the help.
Good News Jail & Prison Ministry
www.goodnewsjail.org
mcmcomasp
Contributor
6834 Points
1436 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 06:57 PM|LINK
to create a popup window you need javascript
(javascript:window.open('myPopup.aspx",other properties here)
this site will make the js you need for a popup window : http://javascript.internet.com/generators/popup-window.html
you should not need to call it from codebehind you just call it from client side javascript.
this is what i use all the time :
function genericPopup(href, width, height, scrollbars){ var param = "width="+width+", height="+height+", scrollbars="+scrollbars+", resizable, status"; return window.open(href, "", param);}
then i just pass it the href (url), width, height, and if we want scroll bars or not.
to call it from a link you would use
<a href="MyDestinationPage.aspx" onClick="genericPopup(this.href,300,300,no)">Click for popup</a>
if you NEED to call it from serverside you need to inject the javascript into codebehind and use RegisterClientScriptBlock method (which is complicated) if you can avoid doing it from code-behind i would.
mcm
xxwhocaresxx
Member
32 Points
22 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:13 PM|LINK
A message box or a popup window is not available in asp.net. You could use javascript or if you have AJAX the modal popup extender is a great control.
Haissam
All-Star
37421 Points
5632 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:19 PM|LINK
Create a form call it WebForm2.aspx, on WebForm1.aspx add a button with id Button1. onpage_load event use the below code
Button1.Attributes.Add("onclick","window.open('WebForm2.aspx','','height=300,width=300');return false")
HC
MCAD.NET
| Blog |
Chaplain Dou...
Member
305 Points
934 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:22 PM|LINK
Thanks Haissam. You have been of much help to me today. I will give your "popup" suggestion a try.
Good News Jail & Prison Ministry
www.goodnewsjail.org
Chaplain Dou...
Member
305 Points
934 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:24 PM|LINK
I suspect that javascript will not work on my Windows 2003 Server running asp.net 2.0???
Good News Jail & Prison Ministry
www.goodnewsjail.org
mcmcomasp
Contributor
6834 Points
1436 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:27 PM|LINK
javascript works on almost everything. its dependant on the CLIENT not the server. and 99% of all web clients have some form of javascript installed.
mcm
Haissam
All-Star
37421 Points
5632 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 07:42 PM|LINK
Javascript wont work except if the client has his/her web browser javascript disabled other than this it should work.
Remember javascript is client side scripting language which means it runs on the client machine and not on the server.
MCAD.NET
| Blog |
Chaplain Dou...
Member
305 Points
934 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 09:23 PM|LINK
Suppose that I want to pass some text content to the WebForm2.aspx file that is opened by your example. How would I pass this text information? What I am trying to do is display a particular message (which will come from a database and hence is not fixed) in the pop up window. Thanks for your continued help.
Good News Jail & Prison Ministry
www.goodnewsjail.org
Haissam
All-Star
37421 Points
5632 Posts
Re: How to Create and Call a Popup Window
Dec 05, 2007 10:07 PM|LINK
You can save the string in a session variable which can be read in webform2 to be displayed. Take a look into the below example.
// WebForm1 page_load event
Session["Test"] = "Hello World";
Button1.Attributes.Add("onclick","window.open('WebForm2.aspx','','height=300,width=300');return false");
// WebForm2.aspx page_load event
Response.Write(Session["Test"].ToString());
MCAD.NET
| Blog |