Good Afternoon. Please forgive me for my lack of knowledge on AJAX. I am learning this because my work asked me to and I am trying work with the the TAB Control.
I have a database table that has a category field and a question field. I am able to popuplate the name of the tab when I select a disctinct category, but when I try to add something for the Content Template I receive an error. My final goal is for someone to choose one of the tabs (based off of my categories) and display a list of questions. All coming from a database table. Please look at this image and let me know what I am doing wrong.
Thanks in advance
You cannot use ContentTemplate like that. ContentTemplate is the set of controls to display under the tab (body), not the label of the tab itself.
.HeaderText = "Jason" would put the text Jason in the tab.
I have already got the label name populated with the distinct cateogry. I am trying to figure out how to populate the body of each label with the appropriate questions from the database. I just put "jason" in to see if I would get the same error and I did.
In my while loop I generate the headertext of the label with CategoryNames("Category") When I try to populate the ContentTemplate with ("jason") or I try to make a call to the database to get all the questions that are associated to the category name, I get that error that I posted.
I hope I am making sense.
Thanks
This is an example of how to populate a tab dynamically. I must accept this is not very intuitive nor there is documentation about this.
==========================
Default.aspx
==========================
<%
@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %><!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
headrunat="server"><title>Untitled Page</title></
head><
body><formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><div><ajaxToolkit:TabContainerID="TabContainer1"runat="server"></ajaxToolkit:TabContainer> </div></form></
body></
html>============================
Default.aspx.cs
===========================
using
System;using
System.Data;using
System.Configuration;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;public
partialclass_Default : System.Web.UI.Page{
protectedvoid Page_Load(object sender,EventArgs e){
if (!this.IsPostBack){
int n = 3;while (n > 0){
AjaxControlToolkit.
TabPanel oTabPanel =new AjaxControlToolkit.TabPanel();TabContainer1.Tabs.Add(oTabPanel);
oTabPanel.ContentTemplate = Page.LoadTemplate(
this.TemplateSourceDirectory +"\\WebUserControl.ascx");WebControl oWB =newWebControl(HtmlTextWriterTag.Div);oTabPanel.ContentTemplate.InstantiateIn(oWB);
oTabPanel.HeaderText =
"Test" + n.ToString();oTabPanel.SetRenderMethodDelegate(RenderA);
n--;
}
}
}
privatevoid RenderA(HtmlTextWriter output,Control container){
output.WriteLine((
"Position ") + ((AjaxControlToolkit.TabPanel)container).HeaderText);
}
}
=====================================
WebUserControl.ascx
=====================================
<%
@.ControlLanguage="C#"AutoEventWireup="true"CodeFile="WebUserControl.ascx.cs"Inherits="WebUserControl" %><
ajaxToolkit:TabPanelID="TabPanel1"runat="server"><
ContentTemplate></ContentTemplate><
HeaderTemplate></HeaderTemplate></
ajaxToolkit:TabPanel>=====================================
WebUserControl.ascx.cs
=====================================
using
System;using
System.Data;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;public
partialclassWebUserControl : System.Web.UI.UserControl{
protectedvoid Page_Load(object sender,EventArgs e){
}
}
Thank you, This is going to sound bad, but I don't know C# so I will need to transfer this to VB.
Thanks Again, I will try first thing monday morning.
I've been trying to use this method but there seems to be some code missing -
In oTabPanel.SetRenderMethodDelegate(RenderA) what should be passed to RenderA?
Thanks
No comments:
Post a Comment