This is a migrated thread and some comments may be shown as answers.

Open Radwindow from Global.asax file

4 Answers 106 Views
Window
This is a migrated thread and some comments may be shown as answers.
Noor hussain
Top achievements
Rank 1
Noor hussain asked on 24 Jun 2011, 08:27 AM
Dear All,

Please let me know if its possible to open RadWindow using severside code from  Application_start event of Global.asax. I am trying to open the radwindow in a callback method of cache item whenever the cache item expires. Please find the code below for your reference. Any help will be appreciated.

Regards,
Noor Hussain
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
        RegisterCacheEntry()
    End Sub
 
''' <summary>
    ''' Register a cache entry which expires in 1 minute and gives us a callback.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub RegisterCacheEntry()
        ' Prevent duplicate key addition
        If HttpContext.Current.Cache(DummyCacheItemKey) IsNot Nothing Then
            Return
        End If
 
        HttpContext.Current.Cache.Add(DummyCacheItemKey, "Test", Nothing, DateTime.MaxValue, TimeSpan.FromMinutes(1), CacheItemPriority.NotRemovable, _
         New CacheItemRemovedCallback(AddressOf CacheItemRemovedCallback))
    End Sub
 
    ''' <summary>
    ''' Callback method which gets invoked whenever the cache entry expires.
    ''' We can do our "service" works here.
    ''' </summary>
    ''' <param name="key"></param>
    ''' <param name="value"></param>
    ''' <param name="reason"></param>
    Public Sub CacheItemRemovedCallback(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason)
        Debug.WriteLine("Cache item callback: " & DateTime.Now.ToString())
 
        ' Do the service works
        DoWork()
 
        ' We need to register another cache item which will expire again in one
        ' minute. However, as this callback occurs without any HttpContext, we do not
        ' have access to HttpContext and thus cannot access the Cache object. The
        ' only way we can access HttpContext is when a request is being processed which
        ' means a webpage is hit. So, we need to simulate a web page hit and then
        ' add the cache item.
        HitPage()
    End Sub
 
    ''' <summary>
    ''' Hits a local webpage in order to add another expiring item in cache
    ''' </summary>
    Private Sub HitPage()
        Dim client As New WebClient()
        client.DownloadData(DummyPageUrl)
    End Sub
 
    ''' <summary>
    ''' Asynchronously do the 'service' works
    ''' </summary>
    Private Sub DoWork()
        Debug.WriteLine("Begin DoWork...")
        Debug.WriteLine("Running as: " + WindowsIdentity.GetCurrent().Name)
 
 
       
        Dim RadWindowManager1 As New RadWindowManager
        
 
 
        'Set the same height to all windows
        RadWindowManager1.Height = Unit.Pixel(250)
 
 
        'Add shortcuts to radwindow manager clientside commands
        RadWindowManager1.Shortcuts.Add(New WindowShortcut("MinimizeAll", "ALT+F2"))
        RadWindowManager1.Shortcuts.Add(New WindowShortcut("RestoreAll", "ALT+F3"))
 
        'Create a new window add it dynamically
 
        'The window will inherit the default settings of parent WindowManager
        Dim newWindow As New RadWindow()
        newWindow.NavigateUrl = "www.google.com"
 
         
 
        
 
        'Top and Left can be used in conjunction with the OffsetElementId (if no OffsetElementId is specified, the top left corner of the browser window is used
        newWindow.Top = Unit.Pixel(22)
        newWindow.Left = Unit.Pixel(0)
 
        'Add the newly created RadWindow to the RadWindowManager's collection
        RadWindowManager1.Windows.Add(newWindow)
 
 
        'Get a reference to the first window in the list
        Dim firstWindow As RadWindow = RadWindowManager1.Windows(0)
        'alternative:
        'Telerik.WebControls.RadWindow mywindow = RadWindowManager1.Windows["RadWindowServer"];
 
 
 
        'Set its navigate URl to be different
        firstWindow.NavigateUrl = "www.google.com"
        firstWindow.VisibleOnPageLoad = True
 
         
        
 
        Debug.WriteLine("End DoWork...")
    End Sub

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 Jun 2011, 02:41 PM
Hi Noor,

Please note that this task is not related directly to the Telerik controls. If you are able to add a simple label to the page in this manner you could add a RadWindow by using the same logic.

  Nevertheless here are some pointers on the matter - in the Application Start event there is no Page initialized, there are only a few global applications objects available, such as the Cache. What you can do is use a global variable as a flag, then in the Session Start you could check for this value and create the RadWindow dynamically, show it then reset the flag value so it is not shown anymore. For example:
If flag Then
    Dim wnd As New Telerik.Web.UI.RadWindow()
    wnd.Skin = "Black"
    wnd.VisibleOnPageLoad = True
    TryCast(HttpContext.Current.Handler, Page).Page.Controls.Add(wnd)
    flag = False
End If



Kind regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Noor hussain
Top achievements
Rank 1
answered on 27 Jun 2011, 08:17 AM
Hi Marin,

Thanks a lot for your time. I am able to open the window following the steps suggested by you. But the window is opening only once. I want it to open whenever the session_start event fires i.e whenever the page is requested. Please let me know if this can be done. for you reference I am enclosing my code.
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session is started
        Try
            OpenWindow()
        Catch ex As Exception
 
        End Try
 
    End Sub
 
Private Sub OpenWindow()
        Dim RadWindowManager1 As New RadWindowManager
        
        'Set the same height to all windows
        RadWindowManager1.Height = Unit.Pixel(250)
 
 
        'Add shortcuts to radwindow manager clientside commands
        RadWindowManager1.Shortcuts.Add(New WindowShortcut("MinimizeAll", "ALT+F2"))
        RadWindowManager1.Shortcuts.Add(New WindowShortcut("RestoreAll", "ALT+F3"))
 
        'Create a new window add it dynamically
 
        'The window will inherit the default settings of parent WindowManager
        Dim newWindow As New RadWindow()
        newWindow.NavigateUrl = "www.google.com"
 
         
 
        'Top and Left can be used in conjunction with the OffsetElementId (if no OffsetElementId is specified, the top left corner of the browser window is used
        newWindow.Top = Unit.Pixel(22)
        newWindow.Left = Unit.Pixel(0)
 
        'Add the newly created RadWindow to the RadWindowManager's collection
        RadWindowManager1.Windows.Add(newWindow)
 
 
        'Get a reference to the first window in the list
        Dim firstWindow As RadWindow = RadWindowManager1.Windows(0)
       
 
 
 
        'Set its navigate URl to be different
        firstWindow.NavigateUrl = "www.google.com"
        firstWindow.VisibleOnPageLoad = True
        TryCast(HttpContext.Current.Handler, Page).Page.Controls.Add(firstWindow)
        
    End Sub


Regards,
Noor hussain 
0
Marin Bratanov
Telerik team
answered on 28 Jun 2011, 08:42 AM
Hello Noor,

I am not sure that this behavior is related to the RadWindow. Please try debugging your code to see if this event is hit when a new session is opened. Also please make sure that you actually open new sessions as accessing the site from the same computer may not alway open a new one. You could also try this with a different control, for example a literal or label. If it is working for it then it should work for the RadWindow as well. I would also advise using the simpler version I sent instead of adding a window manager and using it windows array directly, as it is possible that this object is persisted in the server memory and thus the array would increase over time and you would get some unexpected behavior.


Regards,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Noor hussain
Top achievements
Rank 1
answered on 02 Jul 2011, 06:20 AM
Hello Marin,

Thanks a lot. I will go through your suggestion.

Regards,
Noor Hussain
Tags
Window
Asked by
Noor hussain
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Noor hussain
Top achievements
Rank 1
Share this question
or