Solved

ASP.NET and popup windows with dynamic URLs

Posted on 2003-10-30
3
779 Views
Last Modified: 2010-08-05
Hi there:

Newbie here and I must not be understanding something fundamental.

I can pop up a window if I RegisterClientScriptBlock in the Page_Load method.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim popupScript As String = "<script language='JavaScript'> function DoClick(){ window.open('test.aspx','PopUp','location=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes') }<" & "/script>"
        Page.RegisterStartupScript("PopupScript", popupScript)

'snip

End Sub

This works fine but I want to give a name-value pair like test.aspx?name=value.  Value will be found by firing a MenuItemClicked event, which will then read the contents of a cell of an active row of a grid.

Private Sub UltraWebMenu1_MenuItemClicked(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebNavigator.WebMenuItemEventArgs) Handles UltraWebMenu1.MenuItemClicked

Dim row As Infragistics.WebUI.UltraWebGrid.UltraGridRow
Dim iProfileKey As Integer

Select Case e.Item.Text

case "Profile"
  row = UltraWebGrid1.DisplayLayout.ActiveRow
  iProfileKey = CInt(row.Cells(0).Text)

  Dim popupScript As String = "<script language='JavaScript'> function DoClick(){ window.open('test.aspx?=iProfileKey" & iProfileKey & "','PopUp','location=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes') }<" & "/script>"
        Page.RegisterStartupScript("PopupScript", popupScript)

end Select

End Sub

However, this doesn't work.  How can you popup a window given a dynamic URL?  Must RegisterClientScriptBlock be in Page_Load?
0
Comment
Question by:wym
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
CuSo4 earned 50 total points
ID: 9654134
The problem is that your JavaScript have to be constructed BEFORE the MenuItemClicked event is fired. In your code it's only constructed after the MenuItemClicked event is clicked, so it has no effect, because the JavaScript DoClick() method is called before the postback to the server, and thus before that the MenuItemClicked event click is runned.
So what happens when I click on the MenuItem:

1.) The Javascript DoClick() function is called. (which, in this case does not exists, because it haven't be created yet)
2.) The Page is posted back to the server, and the Page_Load method is fired
3.) Your UltraWebMenu1_MenuItemClicked method is fired
4.) The HTML-code is constructed and sent back to the client. (At this point your javascript will probably exist too, but it won't be a dynamic url, it will be the url that was generated on the previous postback...)
0
 
LVL 2

Expert Comment

by:CuSo4
ID: 9654178
I don't know exactely if it works with UltraWebGrid, but I know for a button you can easily create a popup using a dynamic url. If e.g. your button is named "btnMenu", you can add this code to your Page_Load:

//Generate some code that will create the url and store it in dynURL

btnMenu.Attributes.Add("onClick", "javascript:window.open('" & dynURL & "','_blank','width=400,height=550, left=312,top=100');")
0
 

Author Comment

by:wym
ID: 9658010
Thank you CuSo4.  Once I understood the problem, I could fix it!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now