Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Saturday, March 24, 2012

Triggers for UpdatePanel

I am just learning how to use the UpdatePanel control, so please be patient with me.

I think I understand the concept of wiring ControlID/EventName combinations to the UpdatePanel's collection of triggers.

It seems fairly straight forward if you are wiring up a standard Button control, but in my case, I would like to wire a button control embedded in a user control or DataGrid control. I attempted to expose the button as a public property of the user control and tried to wire it up ("UserControl.MyButton" and "Click"), but I get the

"A control with ID 'WebUserControl1.MyButton' could not be found for the trigger in UpdatePanel 'UpdatePanel1'. "

error message.

I also would like to do the same with a button embedded in a datagrid, but that seems to be a tall order.

Thanks much in advance.

It seems strange at first but you can add the usercontol/datagrid (the button's parent control) as a trigger for the updatepanel. Maybe that is enough for you.

(You can also force the updatepanel to refresh in the server side: you handle your button click event server side and then simple call the update method of any updatepanel to your taste)


stmarti:

It seems strange at first but you can add the usercontol/datagrid (the button's parent control) as a trigger for the updatepanel. Maybe that is enough for you.

(You can also force the updatepanel to refresh in the server side: you handle your button click event server side and then simple call the update method of any updatepanel to your taste)

Could you give me an example of what the code ought to look like? I am not following you. Thank you.


hello.

well, just pass the id of the grid instead of passing the id of the button you've defined on the template.


Thanks. Works.

Wednesday, March 21, 2012

Trying to Dynamically Populate a Tab

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

Error

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