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.
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 22 Dec 2011, 06:57 AM
Hello,
Try the following code snippet.
CS:
Thanks,
Princy.
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.
0
Sy
Top achievements
Rank 1
answered on 22 Dec 2011, 06:43 PM
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.
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.
0
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
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
0
Sy
Top achievements
Rank 1
answered on 24 Dec 2011, 04:20 AM
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
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?
<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?
0
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
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
0
Sy
Top achievements
Rank 1
answered on 27 Dec 2011, 07:58 PM
You're right. I had thought that the Page_Onload event occurred first. Still, it was an excellent idea to use the Session variable.