Problem with "show" method

6 posts, 0 answers
  1. Tom
    Tom avatar
    3 posts
    Member since:
    Oct 2012

    Posted 26 Oct 2012 Link to this post

    Hi,

    am using telerik notification for client-side validation. i have a rad button in my aspx page like this:
    <telerik:RadButton ID="testButton" runat="server" Text="Click Me!" OnClientClicking="ValidateJScript();"></telerik:RadButton>
    and a telerik notification like this:
    <telerik:radnotification id="notification" runat="server"> </telerik:radnotification>

    i'm trying to validate my fields one by one in a JScript file. but for simplicity let's say i just want to display "Hello World" in the telerik notification using the "ValidateJScript()" Java Script function like this:
    function ValidateJScript() {
    var notification = $find( '<%=RadNotification.ClientID %>');
    var message = 'Hello World';
    notification.text = message;
    alert(notification.text);
    notification.show();
    first problem i encountered was that "set_text" method didn't work, and so i used ".text =" and that worked. Same goes for "set_title".
    i made sure that ".text =" worked using the "alert(notification.text); statement. However,"notification.show();" never got executed at all, and i was never able to show the notification at all. moreover, if i add some test alert message after the "notification.show();" statement it never gets executed either. so can anyone help me and tell me how to get the notification to show using javascript in my scenario, and why did the "set_text" and "set_title" methods never worked here? thanks!


  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2012 Link to this post

    Hi Tom,

    I tried to replicate the issue in 2012, 3, 1016, 35 version and is working as expected at my end. Following is the sample code that I tried which worked as expected.

    ASPX:
    <telerik:RadButton ID="testButton" runat="server" Text="Click Me!" OnClientClicking="ValidateJScript">
    </telerik:RadButton>
    <telerik:RadNotification ID="notification" runat="server">
    </telerik:RadNotification>

    JS:
    <script type="text/javascript">
        function ValidateJScript() {
            var notification = $find('<%=notification.ClientID %>');
            var message = 'Hello World';
            notification.set_title("Error Notification");
            notification.set_text(message);
            notification.show();
            alert(notification._text);
            alert(notification._title);
        }
    </script>

    I also advise that you upgrade to the latest version, as there have been some fixes on the RadNotification control and they may help you, as I am not sure exactly what and how you are using.

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tom
    Tom avatar
    3 posts
    Member since:
    Oct 2012

    Posted 30 Oct 2012 Link to this post

    thank you it is solved now.

    one more question though, if i'm to show a newline using Jscript, the notification will NEVER show now! Any idea?

    var message= "";
      
    message = "Hello \n";
          
    message = message + "World";
     
    notification.set_text(message);
     
    notification.show();

  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 31 Oct 2012 Link to this post

    Hi Tom,

    The most likely reason for your problems is a JavaScript error on the page. The original was due to the incorrectly attached handler to the RadButton and more information about that can be found in this blog post.

    Regarding the new lines - the notification takes an HTML string, so the new line character is <br /> and the following snippet works fine with me:
    <script type="text/javascript">
        function ValidateJScript()
        {
            var notification = $find('<%=notification.ClientID %>');
            var message = 'Hello<br />World';
            notification.set_title("Error Notification");
            notification.set_text(message);
            notification.show();
        }
    </script>
    <telerik:RadButton ID="testButton" runat="server" Text="Click Me!" AutoPostBack="false"
        OnClientClicking="ValidateJScript">
    </telerik:RadButton>
    <telerik:RadNotification ID="notification" runat="server" Width="200px" Height="100px">
    </telerik:RadNotification>



    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.
  6. Tom
    Tom avatar
    3 posts
    Member since:
    Oct 2012

    Posted 31 Oct 2012 Link to this post

    Thank you so much! This worked like a treat, but!
    if i place the Jscript in a seperate file and i add that regularly to my page, the same problem occurs and my radnotification is never recognized. (but the document can find it: like if i write alert(notification.title) for example it displays it correctly in the alert, but "show" and all other methods of the notification won't work. any idea?
  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 01 Nov 2012 Link to this post

    Hello Tom,

    The way a reference to the notification is obtained includes server code blocks which cannot be used in external files, as they have to be parsed by the server. Thus, your code throws a JavaScript error because of the incorrect reference.

    What I can advise is that you keep a function that will return this reference in the aspx page and call that from the external file instead of using directly $find() there.


    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017