Issue in User Control

9 posts, 0 answers
  1. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 05 Nov 2012 Link to this post

    Hi, im using a RadNotification in a user control (ascx). The control is loaded dynamically on the page either in a placeholder or in a RadTabStrip (both methods are experiencing the issue). It seems I cant define any property of the RadNotification in code-behind except at Page Loading/Init (I try to set the Title, Text and ContentIcon based on some conditions before calling .Show() ). I also tried fixing the user control on the page (not dynamically loaded) and still same issue.

     I try the same on another page where RadNotification is fixed on the page (not in user control) and then it works good.

    Any idea?

    TIA
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 06 Nov 2012 Link to this post

    Hello Martin,

    It seems like you have some AJAX functionality and the button/control that initiates the AJAX request does not update the notification control. If this is the case then you are experiencing the expected behavior of the MS AJAX framework. You would need to include the notification in the partial postback in order to change its properties. Also, when creating a control dynamically you need to make sure you re-create it with every postback and with the same ID.

    All the best,
    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. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 06 Nov 2012 Link to this post

    Thanks Marin,

    the following solved the problem

    protected void Page_Load(object sender, EventArgs e)
    {
       manager = RadAjaxManager.GetCurrent(Page);
       manager.AjaxSettings.AddAjaxSetting(manager, RadNotification1);
       manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager_AjaxRequest);
    }

  5. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 16 Nov 2012 Link to this post

    Hi Martin

    I have the same issue, but your solution doesn't work. I get an error on the manager.AjaxRequest +=....
    Says its an event and cannot be called directly.
    Any ideas?

    Andy
  6. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 16 Nov 2012 Link to this post

    Andy,

    Personally, ive never encounter such error. Probably the admin will know better. What I can tell you is make sure that "RadAjaxManager_AjaxRequest" is defined:

    protected void RadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
    ....
    }

    In my case, my user control is using a RadAjaxManagerProxy and the parent page contains the RadAjaxManager. Post your code here since its probably what they will ask you.

    Martin
  7. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 16 Nov 2012 Link to this post

    Thanks Martin
     When the Mods pick this up here is my code.

    I have a radAjaxManager on the parent page. If I have the notification on the parent page with the function in that pages code behind, it works OK.

    This is the control
    <asp:ScriptManagerProxy ID="ScriptManagerProxy" runat="server"></asp:ScriptManagerProxy>
     
    <telerik:RadNotification ID="rnNotification" runat="server"  Height="100px"  Width="300px"  VisibleOnPageLoad="True" EnableEmbeddedSkins="false" Skin="Activity"  ></telerik:RadNotification>

    This is the Notification - still in dev at the moment so some params will change.

    This is the cod hehind for the control
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
     
            Dim manager = RadAjaxManager.GetCurrent(Page)
            manager.AjaxSettings.AddAjaxSetting(manager, rnNotification)
     
            'manager.AjaxRequest += New RadAjaxControl.AjaxRequestDelegate(RadAjaxManager_AjaxRequest)
     
     
            'config the notifier
            rnNotification.TitleIcon = ""
            rnNotification.Title = ""
            rnNotification.ContentIcon = "../App_Themes/Images/Info_32.png"
     
        End Sub

    Its the manager.ajaxsettings that commentout that errors.

    This is a simple function to set the message - will be eplaced with a DB function.
    Public Sub GetNotifications(Location_ID As Int32)
     
        rnNotification.Show("New person here! " + Location_ID)
     
    End Sub

    And as suggested I have this empty function
    Protected Sub RadAjaxManager_AjaxRequest(sender As Object, e As AjaxRequestEventArgs)
     
     
    End Sub

    Andy
  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 16 Nov 2012 Link to this post

    Hello Andy,

    It is not always necessary to add the AjaxRequest handler dynamically, so you can simply remove this last line and set the handler in the markup if you find it more suitable. You can access the controls in the code-behind through the FindControl method.

    What is important is that you include the RadNotification in the list of updated controls when you want to change its settings. More details on dynamic creation of AJAX settings is available here:
    http://www.telerik.com/help/aspnet-ajax/ajax-add-ajaxsettings-programmatically.html

    You can also declare AJAX settings in the markup if your notificartion is in the same INaming container as the ajax manager (I cannot confirm this with just a few snippets, so I am just throwing in an idea).

    Nevertheless, back to the main issue - it seems you are using VB, so you should adapt the C# syntax (http://msdn.microsoft.com/en-us/library/t3d01ft1(v=vs.100).aspx):
    AddHandler manager.AjaxRequest, AddressOf RadAjaxManager_AjaxRequest

    I am also attaching here a simple sample I built on top of your snippets.

    Kind 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.
  9. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 19 Nov 2012 Link to this post

    Thanks Marin

    I'll try this and let you know.

    Yes my project is VB, but the code is what came out of your code converter.

    Andy
  10. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 21 Nov 2012 Link to this post

    Hi Andy,

    I hope things will work out well for you. As for the code converter - this is still automated software and like all such converters may not be 100% accurate. Adding a handler dynamically is a general programming task, so the developer should be able to overcome such issues, as information on the matter is freely available in the net.

    All the best,
    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