How to show RadWindowManager.RadAlert from Sshared method

3 posts, 1 answers
  1. Kosta
    Kosta avatar
    4 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    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. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 07 Feb 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kosta
    Kosta avatar
    4 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    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");
    }


Back to Top