[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 800
  • Last Modified:

ASP.NET and popup windows with dynamic URLs

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
wym
Asked:
wym
  • 2
1 Solution
 
CuSo4Commented:
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
 
CuSo4Commented:
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
 
wymAuthor Commented:
Thank you CuSo4.  Once I understood the problem, I could fix it!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now