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

How to show RadWindowManager.RadAlert from Sshared method

2 Answers 221 Views
Window
This is a migrated thread and some comments may be shown as answers.
Kosta
Top achievements
Rank 1
Kosta asked on 07 Feb 2013, 02:42 PM
Hi,

How to display RadWindowManager.RadAlert from shared ( static ) method. My scenario is as follows:

1. When a user click on a button a java script function is executed with that code:
Page.ClientScript.RegsterStartupScript(Me.GetType(), "alert", "OpenActiveX();", True)

2. After javascript function finished its work I call a static function into asp.net code behaind with PageMethods
function OpenActiveX() {
    try {
        var xml = document.getElementById('MainContent_XmlTextReference').value;
        ...
        PageMethods.SaveXmlFile(xml)
    }
    catch (Err) {
        alert(Err.description);
    }
}

and here is how SaveToXml method is defined

<Services.WebMethod()> _
    Public Shared Function SaveXmlFile(ByVal xml As String) As Boolean
        ' work with returned from java script data
 
         Here need to display an alter when work with data is finished
 
        Return True
    End Function


I have 

Public Class MyPage
    Inherits System.Web.UI.Page
 
    Private Shared MyPageHandle As MyPage
 
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Try
                MyPageHandle = Me
                ...
        End If
    End Sub
 
    <Services.WebMethod()> _
    Public Shared Function SaveXmlFile(ByVal xml As String) As Boolean
        ...
 
        MyPageHandle.RadWindowManager1.RadAlert("test", 100, 100, "test", 0)
 
        Return True
    End Function
End Class

add a RadWindowManager to web page named and after that try to call it from shared method
without success

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 07 Feb 2013, 03:39 PM
Hello Kosta,

The following line will cast the handler from the shared method to a page:
Dim currentPage As Page = DirectCast(HttpContext.Current.Handler, Page)

You would then need to find the RadWindowManager in the code-behind (e.g. Page.FindControl()):
Dim currentPage As Page = DirectCast(HttpContext.Current.Handler, Page)
DirectCast(currentPage.FindControl("RadWindowManager1"), Telerik.Web.UI.RadWindowManager).RadAlert("test", 100, 100, "test", "")

What I can advise is using the JavaScript onSuccess handler to simply call the radalert() client-side method. You can return the needed data as a string instead of a boolean value. If more than one string is needed you can concatenate them with a special symbol (e.g. "|") and split it on the client to get the necessary arguments.

Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Kosta
Top achievements
Rank 1
answered on 07 Feb 2013, 07:55 PM
Thank you, Marin,

I modified my javascript code to and now works great.
function OpenActiveX() {
    try
        var xml = document.getElementById('MainContent_XmlTextReference').value;
        ...
        PageMethods.SaveXmlFile(xml, onSuccess)
    }
    catch (Err) {
        alert(Err.description);
    }
}
 
function onSuccess(pageMethodReturnValue, importantValue) {
    radalert("Finish", "350", "150", "alert");
}


Tags
Window
Asked by
Kosta
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Kosta
Top achievements
Rank 1
Share this question
or