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
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