How to Create and Call a Popup Window

Last post 01-13-2010 8:27 PM by cnsuman. 21 replies.

Sort Posts:

  • How to Create and Call a Popup Window

    12-05-2007, 2:10 PM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    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
  • Re: How to Create and Call a Popup Window

    12-05-2007, 2:57 PM
    Answer
    • Contributor
      6,734 point Contributor
    • mcmcomasp
    • Member since 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,385

    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

  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:13 PM
    Answer
    • Member
      32 point Member
    • xxwhocaresxx
    • Member since 10-12-2007, 3:17 PM
    • Posts 22

     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.

  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:19 PM
    Answer
    • All-Star
      37,391 point All-Star
    • Haissam
    • Member since 10-05-2006, 6:25 AM
    • Beirut - Lebanon
    • Posts 5,632

    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

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:22 PM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    Thanks Haissam.  You have been of much help to me today.  I will give your "popup" suggestion a try.

    Dr. Douglas Pruiett
    Good News Jail & Prison Ministry
    www.goodnewsjail.org
  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:24 PM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    I suspect that javascript will not work on my Windows 2003 Server running asp.net 2.0???

    Dr. Douglas Pruiett
    Good News Jail & Prison Ministry
    www.goodnewsjail.org
  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:27 PM
    • Contributor
      6,734 point Contributor
    • mcmcomasp
    • Member since 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,385

    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

  • Re: How to Create and Call a Popup Window

    12-05-2007, 3:42 PM
    • All-Star
      37,391 point All-Star
    • Haissam
    • Member since 10-05-2006, 6:25 AM
    • Beirut - Lebanon
    • Posts 5,632

    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.

     

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
  • Re: How to Create and Call a Popup Window

    12-05-2007, 5:23 PM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    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
  • Re: How to Create and Call a Popup Window

    12-05-2007, 6:07 PM
    • All-Star
      37,391 point All-Star
    • Haissam
    • Member since 10-05-2006, 6:25 AM
    • Beirut - Lebanon
    • Posts 5,632

    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());

     

    Haissam Abdul Malak
    MCAD.NET
    | Blog |
  • Re: How to Create and Call a Popup Window

    12-05-2007, 8:15 PM
    • Member
      545 point Member
    • cafeasp
    • Member since 04-13-2007, 12:18 AM
    • Posts 101

    Check this link http://apriendavisualstudio.net/?p=21

     It's a video How-to add javascript (pop up window) to a ASP.NET button with 1 line of code.  You can even add other cool stuff to the button.  Sample code is available for download. 

    Keep it simple !
  • Re: How to Create and Call a Popup Window

    12-06-2007, 10:21 AM
    • Contributor
      6,734 point Contributor
    • mcmcomasp
    • Member since 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,385

    or you could just make a database call on the load event of the new page your opening.  it doesn't matter that javascript is opening it, its still a normal Aspx page.  So you can just make it get the data from the database when it loads (like any other page)

    mcm

  • Re: How to Create and Call a Popup Window

    12-06-2007, 11:04 AM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    The session variable is good.  But I will be having a variable number of controls that will need to use this pop up window.  Each control will have different text I need to display in the pop up window.  Hence, using a single session variable will not work, unless there is a way to assign a value to the session variable when I "click" the control and before the pop up page is displayed.  Have any ideas??

    Dr. Douglas Pruiett
    Good News Jail & Prison Ministry
    www.goodnewsjail.org
  • Re: How to Create and Call a Popup Window

    12-06-2007, 5:22 PM
    • Participant
      841 point Participant
    • kotor2000
    • Member since 04-18-2007, 8:05 PM
    • Qc, Canada
    • Posts 212

    use an asp control and add this in your code-behind :  

     
    'Any value you want to put in session variables
    'Any process you want to do 
    
    Dim strPop As String = "<script language='javascript'>" & vbCrLf _
    & "window.open(YourPAge.aspx','Report');" & vbCrLf _
    & "</script>" & vbCrLf
    ClientScript.RegisterStartupScript(Me.GetType(), "Pop", strPop)
     
    'Anything after this point won't be reach by your application
    
     

    Hope it helps

    Kotor2000
  • Re: How to Create and Call a Popup Window

    12-06-2007, 7:12 PM
    • Member
      165 point Member
    • Chaplain Doug
    • Member since 10-09-2007, 3:27 PM
    • Richmond, Virginia
    • Posts 687

    I would love to use this, but without an explanation of what it does and how to use it, I am dead in the water.

    I need to be able to open a pop up menu or aspx page and pass it information when I click on a label control.  How will this accomplish that?  Thanks.

    Dr. Douglas Pruiett
    Good News Jail & Prison Ministry
    www.goodnewsjail.org
Page 1 of 2 (22 items) 1 2 Next >