How to access a RadAjaxPanel within a FormView

7 posts, 0 answers
  1. Sy
    Sy avatar
    6 posts
    Member since:
    Nov 2011

    Posted 21 Dec 2011 Link to this post

    I am trying to alter the visibility of a RadAjaxPanel that is within an ASP FormView. Please suggest an approach that works; the following approach does not:

    FormView 

    fv = form1.FindControl("FormView1") as FormView;

    RadAjaxPanel myPanel = fv.FindControl("ThePanelOfInterest") as RadAjaxPanel;

    myPanel.Visible = true;

    myPanel is always shown as null even though it does exist.

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

    Posted 22 Dec 2011 Link to this post

    Hello,

    Try the following code snippet.
    CS:
    protected void Page_Load(object sender, EventArgs e)
     {
       RadAjaxPanel Panel1 = (RadAjaxPanel)FormView1.FindControl("RadAjaxPanel1");
       Panel1.Visible = true;
     }

    Thanks,
    Princy.
  3. Sy
    Sy avatar
    6 posts
    Member since:
    Nov 2011

    Posted 22 Dec 2011 Link to this post

    Thanks for your response--it worked. However, there is another wrinkle to this problem. I'm using an NHibernate data source to retrieve data to populate various Telerik fields on my aspx form. Based on the data retrieved, the panel in question may be hidden or made visible. To determine the panel's visibility, I have placed the relevant code inside the DataSource_Selected event handler--which is called after the onLoad event. Your code works in the onLoad event but not in the onSelected event.

    If I place the code now in the DataSourceSelected event handler inside of the onLoad event handler, how will I retrieve the ObjectDataSourceStatusEventArgs parameter? Without this parameter I will not have access to the NHibernate data class that it contains. Am I missing something? Please advise. And thanks again.

     

  4. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 23 Dec 2011 Link to this post

    Hello Sy,

    Please share bigger portion of your code, so all people who want to assist you to have a better understanding of your case.

    The ASPX and code behind files should be good for a start.


    Regards,
    Andrey
    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
  5. Sy
    Sy avatar
    6 posts
    Member since:
    Nov 2011

    Posted 23 Dec 2011 Link to this post

    First, in the aspx page I have an NHibernate reference to a data access class:

    <xyz:NHibernateDataSource IDPropertyName="ItemID" ID="NHibernateDataSourceMyDataClass" runat="server" DataObjectName= "XYZ:NHibernate.MyDataClass, XYZ:NHibernate" OnSelected="DataSource_Selected">
    <SelectParameters>
    <asp:QueryStringParameter Name="objectId" QueryStringField="FolderId" />
    </SelectParameters>
    <xyz:NHibernateDataSource>

    Further down the page there is this Telerik panel:

    <telerik:RadAjaxPanel ID="RadAjaxPanelMyPanel" runat="server" Visible="false" >
    Stuff
    </telerik:RadAjaxPanel>

    Now, based on data in the database this panel may have to be made visible.

    The Page_Load event handler does not have access to the data after the NHibernate class retrieves it. So I have the DataSource_Selected event handler

    DataSource_Selected(

     

    object sender, ObjectDataSourceStatusEventArgs e){...}

     


    The e parameter is used as follows:

    NBIMyDataClass xyzNewClientMatter = e.ReturnValue as NBIMyDataClass;

    Based on what's in xyzNewClientMatter, I want to do the following:

    RadAjaxPanel panelMyPanel = (RadAjaxPanel)FormView1.FindControl("RadAjaxPanelMyPanel");
    panelMyPanel.visible = true;

    Within the DataSource_Selected event handler, panelMyPanel is always null. Within Page_Load it is not; however, the relevant data used to determine whether the panel should be visible is only available in the DataSource_Selected code block, a series of events that occur AFTER the Page_Load event.  That is the problem. Do you have any solutions to suggest?
  6. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 27 Dec 2011 Link to this post

    Hi Sy,

    As the OnSelected event of the NHibernateDataSource is raised before the PageLoad event you could not find the AjaxPanel at this stage because it is not yet added to the controls collection.

    However, you could easily overcome this by getting the desired value in the OnSelected event and to store it  in the Session state, then on the PageLoad  event you could find the AjaxPanel, access the value from the Session state and then toggle the visibility of the AjaxPanel.

    Give this suggestion a try and check whether suits your needs.

    Greetings,
    Andrey
    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
  7. Sy
    Sy avatar
    6 posts
    Member since:
    Nov 2011

    Posted 27 Dec 2011 Link to this post

    You're right. I had thought that the Page_Onload event occurred first. Still, it was an excellent idea to use the Session variable.
Back to Top