Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Wednesday, March 28, 2012

Dynamic Creation of CollapsablePanels

I'd like to know how to create a CollapsablePanel in code-behind. My goal is to fetch records from a SQL 05 DB, and create a panel for each record/row in the dataset. I don't know how many rows I'll have, if any, and this means I need to do it on the back end, not in the XHTML code.

Hi,

I made the following sample according to your requirements, please try it:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { int numberOfRecordsToBeShown = 10; // this value can be determined by the number of rows in database for (int i = 0; i < numberOfRecordsToBeShown; i++) { Panel pnl = new Panel(); Label lblContent = new Label(); LinkButton lbHeader = new LinkButton(); PlaceHolder1.Controls.Add(lbHeader); PlaceHolder1.Controls.Add(pnl); pnl.Controls.Add(lblContent); lbHeader.ID = "Header" + i.ToString(); lbHeader.Text = "Header" + i.ToString(); pnl.ID = "Row" + i.ToString(); lblContent.Text = "Content to be shown"; AjaxControlToolkit.CollapsiblePanelExtender cpe = new AjaxControlToolkit.CollapsiblePanelExtender(); cpe.ID = "Extender" + i.ToString(); cpe.SuppressPostBack = true; cpe.CollapseControlID = lbHeader.ID; cpe.ExpandControlID = lbHeader.ID; cpe.TargetControlID = pnl.ID; PlaceHolder1.Controls.Add(cpe); } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </div> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </form></body></html>
Hope this helps.

I gave it a go, but all I get is 10 lines of 'Content to be shown' on my screen. No collapsing/expanding... nothing, really, except 10 lines of text.


ok, with a few slight alterations, I wound up with this:

protected void Page_Load(object sender, EventArgs e) {
SpewOutCollapses();
}

public void SpewOutCollapses() {
int numberOfRecordsToBeShown = 5; // this value can be determined by the number of rows in database
for (int i = 0; i < numberOfRecordsToBeShown; i++) {
AjaxControlToolkit.CollapsiblePanelExtender cpe = new AjaxControlToolkit.CollapsiblePanelExtender();
StringBuilder sBuild = new StringBuilder();

Panel pnlContainer = new Panel();
Panel pnlHeaderGoal1Update = new Panel();
Label lblContent = new Label();
LinkButton lbHeader = new LinkButton();
PlaceHolder1.Controls.Add(lbHeader);
PlaceHolder1.Controls.Add(pnlContainer);
pnlContainer.Controls.Add(pnlHeaderGoal1Update);
pnlHeaderGoal1Update.Controls.Add(lblContent);

pnlContainer.ID = "pnlContainer" + i.ToString();
pnlContainer.Style.Add("background", "#DFDFDF");

lbHeader.ID = "Header" + i.ToString();
sBuild.Append(" <table class=\"clsOneHundredPercentWide clsBGGreyA clsCursorPointer txtWhiteBold\" style=\"height: 25px;\">");
sBuild.Append(" <tr>");
sBuild.Append(" <td class=\"clsTwoByFivePadding cls25pxHigh clsBold clsLeftAlign\" style=\"width: 15%\">ID " + i.ToString() + "</td>");
sBuild.Append(" <td class=\"clsTwoByFivePadding cls25pxHigh clsLeftAlign\" style=\"width: 85%\">(Show Details...)</td>");
sBuild.Append(" </tr>");
sBuild.Append(" </table>");
lbHeader.Text = sBuild.ToString();

pnlHeaderGoal1Update.ID = "pnlHeaderGoal1Update" + i.ToString();

lblContent.Text = "<div class=\"clsTwoByFivePadding clsLeftAlign\" style=\"padding-right: 10px;\">";
lblContent.Text += " <p>Quisque felis lacus, sodales in, commodo ut, pellentesque sed, orci. Pellentesque congue nisi sed enim. Quisque congue sodales sapien. Suspendisse et lorem ut erat dignissim vestibulum. In hac habitasse platea dictumst. Sed nisl neque, convallis eu, sagittis dignissim, molestie eu, odio. Fusce quam orci, vehicula sollicitudin, tincidunt sed, lobortis dignissim, lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed interdum tincidunt mi. Vivamus blandit molestie lectus. Praesent sem lacus, tincidunt nec, placerat ac, feugiat non, tortor. Donec eu pede in neque viverra iaculis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer interdum augue quis risus. Pellentesque malesuada elit et eros. In ipsum. Pellentesque eget diam. Aenean quis lorem. Cras et dolor at urna pharetra nonummy. Sed posuere, risus eget suscipit lacinia, ipsum nulla adipiscing sapien, vitae aliquet lacus arcu blandit neque.</p>";
lblContent.Text += "</div>";

cpe.ID = "Extender" + i.ToString();
cpe.SuppressPostBack = true;
cpe.CollapseControlID = lbHeader.ID;
cpe.ExpandControlID = lbHeader.ID;
cpe.TargetControlID = pnlHeaderGoal1Update.ID;
PlaceHolder1.Controls.Add(cpe);
}
}

It works great, but that brings me to part 2 of my question: Is there a way to generate SUB collapsers in this... to in effect nest collapsing panels in collapsing panels. I can hard-code that, but I would love to generate it. What I want is, inside the existing panel generation, to generate a single collapsablePanel (so that each collapser has one nested collapser inside). Think that's possible?


Ok, let's forget the nesting for the moment, and think instead about something else: can you explain, possibly, why the panels start fully expanded?


Morydyn:

Ok, let's forget the nesting for the moment, and think instead about something else: can you explain, possibly, why the panels start fully expanded?

By default, the initial state is expanded. You can change it to collapsed explicitly.

cpe.ID = "Extender" + i.ToString();
cpe.Collapsed = true;
cpe.SuppressPostBack = true;

Dynamic Creation of AJAX Controls (w/Intellisense?)

Is there any way to make intellisense work for the AJAX Control Toolkit in the code behind pages? I'm trying to dynamically create controls in c#.

Thanks!

Hi Jerryp,

First , I think you should InstallAsp.Net 2.0 Ajax Extension V1.0 and then installAjax Control Toolkit. You can get them from this url: http://www.asp.net/ajax/ . If your project is an exsit which is not an Ajax-Enabled project, you canmodify the web.config and add reference to the AjaxControlToolkit.dll.

By the way, Javascript intellisense is support by VS2008.

Hope this help.

Best regards,

Jonathan


Thanks for your respnose! I already have all those things installed. I guess I should have given more background. I am trying to create the controls in my c# page_load method. When I dynamically create the controls Intellisense doesn't work, so I've been using Reflector to see what methods are available on the different classes. It doesn't really get annoying until you have to drill down through the class hierarchy to find out what a property is called. My code compiles and runs, but it's difficult to develop with the AJAX Control Toolkit if intellisense doesn't work. I would like to know how to get the intellisense for the control toolkit to work.

Thanks,

Jerry

Dynamic create UpdatePanel during postback

Hi,

I want to add a UpdatePanel into page dynamically during postback, see bellow code for detail. The problem is although UpdatePanel control was successful created, I cannot get its reference in later postback times.

// dummy template
publicclassMyTemplate :ITemplate
{
publicvoid InstantiateIn(Control container)

{

}

}

// create UpdatePanel during postback
protectedvoid Button5_Click(object sender,EventArgs e)
{

Microsoft.Web.UI.UpdatePanel u =new Microsoft.Web.UI.UpdatePanel();

u.ID ="udpDynamic";

u.ContentTemplate =newMyTemplate();

u.Mode = Microsoft.Web.UI.UpdatePanelMode.Conditional;

Microsoft.Web.UI.ControlEventTrigger trigger =new Microsoft.Web.UI.ControlEventTrigger();

trigger.ControlID ="Button6";// this button is created in design time

trigger.EventName =

"Click";

u.Triggers.Add(trigger);

this.Form.Controls.Add(u);

}

// other postback event
protectedvoid Button6_Click(object sender,EventArgs e)
{

Label test =newLabel();

test.Text ="I'm new portlet " +DateTime.Now.ToLongTimeString();

Microsoft.Web.UI.UpdatePanel u = (Microsoft.Web.UI.UpdatePanel)this.Form.FindControl("udpDynamic");

u.Controls.Add(test);// error! u is null

}

// here is HTML code generated, as I can see the UpdatePanel control was created successfully
<div id="udpDynamic"></div>

<components>
<pageRequestManager id="_PageRequestManager" updatePanelIDs="UpdatePanel1,UpdatePanel2,UpdatePanel3,udpDynamic" asyncPostbackControlIDs="Button4,Button6" scriptManagerID="ScriptManager1" form="form1" />
</components>

Well, I can't solve your problem, but I can tell you one thing that is wrong with your code:

When adding a control to an UpdatePanel, you need to use the ContentTemplateContainer.Controls.Add(...) property of the UpdatePanel, otherwise you will not see the control (in a book I read, it will actually throw an error, but I guess it isn't for you).

I work in VB.NET, although I can usually understand C#, but when I try to convert from System.Web.UI.Control (which is what FindControl returns) to System.Web.UI.UpdatePanel, I receive the following error message:

Unable to cast object of type 'System.Web.UI.Control' to type 'System.Web.UI.UpdatePanel'.

I am surprised that you are not receiving this error as well, if you take a look at my posting athttp://forums.asp.net/t/1154222.aspx you can see more details about this problem I am having. Good Luck!

Dynamic controls and problem with UpdateProgress

I dynamically create several LinkButtons, and attach enenthandler for command event, and assign it for triggering Updatepanel. It works, but UpdateProgress doesn't show. I tried to add static button and assign it to updatepanel for triggering, and in this case updateprogress works, so i guess that's everything ok with ajax.

This is code in aspx:

1<asp:PlaceHolder ID="phMenu" runat="server"></asp:PlaceHolder>2<asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server" DisplayAfter="10">3 <ProgressTemplate>4 <span style="color: #ff0066">5 loading... </span>6</ProgressTemplate>7</asp:UpdateProgress>89<asp:UpdatePanel ID="UpdatePanel1" runat="server" >10<ContentTemplate>11<table width="100%" cellpadding=2 cellspacing=0 border=0>12 <asp:Repeater ID="rptFeeds" runat="server" EnableViewState=false>13 <ItemTemplate>14 <tr>15 <td>16 ... some data from db...17 </td>18 </tr>19 </ItemTemplate>20 </asp:Repeater>21 </table></ContentTemplate>22</asp:UpdatePanel>

code-behind in void OnInit:

1foreach (Category catin list)2{3 Panel pnl =new Panel();4 pnl.ID ="menu_" + cat.Id.ToString() ;5 pnl.CssClass ="menu_item";67 LinkButton lb =new LinkButton();8 lb.CommandArgument = cat.Id.ToString();9 lb.Command +=new CommandEventHandler(Clicked);10 lb.ID="trigger_"+cat.Id.ToString();11 lb.Text = cat.Name;12 lb.CssClass ="menu_a";1314 AsyncPostBackTrigger trigger =new AsyncPostBackTrigger();15 trigger.ControlID ="trigger_" + cat.Id.ToString();16 trigger.EventName ="Command";17 UpdatePanel1.Triggers.Add(trigger);1819 pnl.Controls.Add(lb);20 phMenu.Controls.Add(pnl);21}2223protected void Clicked(object sender, CommandEventArgs e)24{25 ChangeCat(Convert.ToInt32(e.CommandArgument));26}

Can you see why UpdateProgess doesn't work?

Hi,hudo

I think it's a normal issue.

You can set the clientclick property of theDynamic controls to show the UpdateProgess.

Thanks


The problem is that the control you want to trigger the UpdateProgress control is not inside the UpdatePanel.

See my post here:http://smarx.com/posts/why-the-updateprogress-wont-display.aspx for an explanation of why that doesn't work.

Dynamic Control creation and viewstate management (client to server)

Hi all,

I am new to AJAX and this is my first port.

In my requirement i need to create set of dynamic controls (multiple instances of a custom webcontrol) to do this i am following the below steps.

    I have a user control with update panel in itI have a button "Add" to add new instance.Hidden field count to check number of dynamic instances addedHidden field to keep track of dynamic id'sRemove button to remove the instanceHandle UpdatePanel Load event to load the previous instance of controls before the control renders
    I have custom web control which inherits the ASP:Table classI override CreateChildControls method to create controls setHidden field to maintain the disabled control ids

rendering dynamic controls and its viewstate is working fine.

I am facing problem here.

I have some business logic in which the if the user selects "Yes" as the option in a RadioButtonList i am disabling few controls in the dynamically rendered sets at clientside. How to I get the controls state in the CreateChildControl method to see what was the control state using the hidden field as i am not able to get the form Posted values at this time. (Note: I know that we can use the UniqueID of the hidden field, but this will not work here as the unique id will be still the control ID unique id will be different when it renders.

So i want to know how to manage the viewstate from client and server in this scenario?

I tried to put in words as simple as possible.

Thanks for the help

- Satish

Missed to add this

When user clicks on "Yes" radio button i am saving the control id in the hidden field where in server side i can see the value in the hidden field at the server side and load the control state (either enabled or disabled). i am having problem here on how to retain the control state from clientside to the server side when it renders.

Thanks

Satish

Dynamic ContentTemplate in the TabPanel

How can i create a dynamic ContentTemplate in the TabPanel control ?

I have the following source:

<asp:ScriptManager ID="scriptManMain" runat="server" EnablePartialRendering="true" />
<ajaxToolkit:TabContainer runat="server" ID="tabContainerMS" CssClass="ajax__tab_xp">
<ajaxToolkit:TabPanel runat="Server" ID="tabPanelMaster" HeaderText="Orders Due Today">
<ContentTemplate>
XXXXXXXXX
<ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

I wanna change the ContentTemplate dynamic by a file .cs on page_load or another function, how can i do that ?

Thank′s

You could use the dynamic population capabilities of the tabpanel control for this which allows you to populate the content of each tab when it is activated via a web service call. Check out the Dynamic* properties on the control.
AjaxControlToolkit.TabPanel tpHome = new AjaxControlToolkit.TabPanel();
tpHome.HeaderText = "Home";
tpHome.ContentTemplate = Page.LoadTemplate("Home.ascx");
tcDefault.Tabs.Add(tpHome);

where tcDefault is TabControl you want this tabPanel to add, so Page.LoadTemplate is the method you should use

Dynamic CollapsiblePanels

I was wondering if anyone has ever dynamically added CollapsiblePanels to a web form based on data from a database? Do I need to create a separate instance for each panel area I need or can I do it with one CollapsiblePanel control? Basically what I am looking to do is create something like the following:

TITLE1
>FIELD1
>FIELD2

TITLE2
>FIELD3
>FIELD4
>FIELD5

All data is being pulled from a database so, the fields are added to a Panel based on the title they are associated with. My workflow is currently to:

1) Query the database to get the information
2) Loop through the records to add controls to a new content panel
3) When all of the fields have been added to the contents panel, create a new CollapsiblePanel control and add it to the form
4) Loop until there aren't any more groups

This seems to kind of work but I continue to get an error stating that I have two or more controls with the same ID. I believe I have traced this to the adding of the multiple CollapsiblePanels. I am generating a random number to assign to the CollapsiblePanel every time one is generated but, the error still happens.

Any ideas what could be going on here?


I was in the same situation and came up with the following code. I hope it helps. I use Patterns and Practices (v3.0) so use your method of choice to obtain the data. I make use of a place holder to dump the controls so make sure you put one on your form and call it plcHolderForPanels for this example. Good luck :)

using System;
using System.Data;
using System.Configuration;
using System.Text;
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;
using Microsoft.Practices.EnterpriseLibrary.Data;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string sql = "SELECT * FROM [topics]";

// Get the topics
IDataReader reader = DatabaseFactory.CreateDatabase().ExecuteReader(CommandType.Text, sql);

// Display the topics
while (reader.Read())
{
GeneratePanels(reader["id"].ToString(), reader["name"].ToString());
}
}
}

private void GeneratePanels(string topicId, string topicName)
{
// 1. Create hte panel for the title
Panel pnlTitle = new Panel();
pnlTitle.ID = @."pnlTitle" + topicId;
pnlTitle.CssClass = "collapsePanelHeader";

Image imgTitle = new Image();
imgTitle.ID = @."imgTitle" + topicId;
imgTitle.ImageUrl = @."images/expand.jpg";

Label lblTitle = new Label();
lblTitle.ID = @."lblTitle" + topicId;
lblTitle.Text = " -- Click here to expand...";

pnlTitle.Controls.Add(imgTitle);
pnlTitle.Controls.Add(new LiteralControl(topicName));
pnlTitle.Controls.Add(lblTitle);

// 2. Create the content panel
Panel pnlContent = new Panel();
pnlContent.ID = @."pnlContent" + topicId;
pnlContent.CssClass = @."collapsePanel";

pnlContent.Controls.Add(new LiteralControl("This is some text..."));

// 3. Now create the collapsible panel control
AjaxControlToolkit.CollapsiblePanelExtender cpe = new AjaxControlToolkit.CollapsiblePanelExtender();
cpe.ID = @."cp" + topicId;
cpe.TargetControlID = pnlContent.ID;
cpe.ExpandControlID = pnlTitle.ID;
cpe.CollapseControlID = pnlTitle.ID;
cpe.Collapsed = true;
cpe.TextLabelID = lblTitle.ID;
cpe.ImageControlID = imgTitle.ID;
cpe.CollapsedImage = "images/expand.jpg";
cpe.ExpandedImage = "images/collapse.jpg";
cpe.SuppressPostBack = true;

plcHolderForPanels.Controls.Add(cpe);
plcHolderForPanels.Controls.Add(pnlTitle);
plcHolderForPanels.Controls.Add(pnlContent);
plcHolderForPanels.Controls.Add(new LiteralControl("<BR><BR>"));
}
}

dynamic cascaded drop down

Hi..

well in my web page based on a parameter user selects i need to create contents dynamically

for eg if A is passed than page will have only 1 drop down but if B is passed it might have 7 8 drop downs in it..

this is one part of the problem..once i am able to create them i need to address there selection index change even which will call again some fucntion

which will reload all othr drop dwon whch were created dynamically

so its kind of generating cascaded drop down dynamically and the parent control id could be more than one

Can some one help me out

in case any one is here wondering what happened to the problem

the solution is same as

http://forums.asp.net/t/1090354.aspx

Dynamic Atlas page

I am making a completely dynamic web page. I want to use Atlas for UI handling.
This means that all atlas controls I create in codebehind (But sometimes a template would be useful, but only html template - atlas code should be generated dynamically). The main idea is that while you enter data, page updates itself and either edits data or changes whole behaviour. So I have some questions
1) Where can I see which classes create which elements in Script tag?
2) Is it possible at all to dynamically change behaviour - for example, to make the same html button call different actions or to completely change part of html (span element) and accordingly change atlas scripts?
3) how to dynamically add atlas controls from codebehind and avoid rendering visible control - make only atlas script?
4) how to make visible part of atlas control to appear somewhere else not after closing HTML tag?It shouldn't work that way, I think. Atlas is more client side then server framework..point is to make smart client webapplications which requests only actually needed data from server. You can create all controls from code, but on client side it will look same as if you create them much easier way in designer.
It's all my personal option

You didn't understand the problem - I want to put more action in client-side. For example, when filling out order form, I want to check data (and autofill some fields) without postback.
But the way I want to build UI is dynamic - I make product definition (what data are necessary for particular product) and screen definition (where these necessary data show up in UI). And then I have helper class that goes through those definitions and creates UI controls. Currently I can create native ASP.NET controls, but I would like to use ATLAS instead.
So the problem is that all examples of ATLAS scripts I have seen so far are statically typed in *.aspx page. But I want to create those scripts at runtime using Microsoft.Web.UI.* classes. But I cannot find all classes that correspond to examples in static scripts. For example, how can I programmatically create serviceMethod tag?
Not all client-side Atlas controls have a server-side version yet. Forexample, there is no serviceMethod Atlas server-control yet.
You would have to write them yourself, or wait until a new version ofAtlas is released which includes more server-controls for the Atlasclient-side controls.

Where can I get more info on how to create a class that creates ATLAS script? What should I inherit from, what methods need to be implemented, etc?

Dynamic Animation

Hi threr;

I want create an show a dynamic animation(exactly like select tag window in this page) using AJAX Control Toolkit animation control. At frist, I dont know how can I create a dynamic animation. Second, I want to call the animation via an event instead of button click.

Hi nima_montazeri,

Check outthis post on how to dynamically create Animations. You can't cause an animation to be played in an event other than those it supports. There is a workaround you could try though. You can create a dynamic OnLoad animation in your event which will play as soon as your page is reloaded - you just have to be careful to clear it out before the next postback.

Thanks,
Ted

Dynamic Ajax Filter C#

I am trying to create a custom ajax filter using code, so far i can filter the textbox with either LowerCaseLetters, or UpperCase etc. but not all 3 and some custom chars. My code at the moment is ;

AjaxControlToolkit.FilteredTextBoxExtender Filter = new AjaxControlToolkit.FilteredTextBoxExtender();
Filter.ID = "Filter" + i.ToString();
Filter.TargetControlID = "NameBox" + i.ToString();
Filter.FilterType = AjaxControlToolkit.FilterTypes.LowercaseLetters;
Filter.FilterType = AjaxControlToolkit.FilterTypes.UppercaseLetters;
Filter.FilterType = AjaxControlToolkit.FilterTypes.Custom;
Filter.ValidChars = " ";
Page.Controls.Add(Filter);

How do you use more than one filter in dynamic filters? thanks John

Hi,

You can use or operator to apply more than one FilterType simultaneously. For example:


Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.LowercaseLetters;
Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.UppercaseLetters;
Filter.FilterType = Filter.FilterType | AjaxControlToolkit.FilterTypes.Custom;


Like this:

Filter.FilterType = AjaxControlToolkit.FilterTypes.Numbers | AjaxControlToolkit.FilterTypes.Custom;
Filter.ValidChars = ".";

Monday, March 26, 2012

dynamic accordionpanes

I'm trying to create dynamic accordion panes for use in an accordion as a menu. I have the controls inside the accordionpanes working, but I'm trying to format the header for the panels and I'm running into a problem. The code is as follows:

dim mypane as accordionpane

'add controls

dim myLabel as label

mylabel.text = "some label"

mypane.controls.add(mylabel)

'add header

mypane.header = new headerTemplate("someheaderlabel","someurl")

myaccorion .pane.add(mypane)

the code for headerTemplate is:

private class headerTemplate

implements itemplate

dim headerlabel as string

dim headerurl as string

public sub new(byval label as string,byval url as string)

headerlabel = label

headerurl = url

end sub

public sub instantiatein (ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn

dim myheader as new literalcontrol

myheader.text = headerlabel

dim myurl as new linkbutton

myurl.text = "(Show All")

myurl.postbackurl = headerurl

container.controls.add(myheader)

container.controls.add(myurl)

end sub

The 'new' sub is run on the 'mypane.header = new headerTemplate("someheaderlabel","someurl") ' line, but the instantiatein is never fired. What am I doing wrong?

OK - I found an easier way to do it - just add the controls to the accordianpane.headercontrols.

Now when I test it (I have 2 hard coded panes and one that I create programatically), the two hard-coded panes expand and collapse fine, but the one i created programatically doesn't collapse (but does make the hard coded ones collapse when i click on it). Has anybody else run across this before? If so, how did you fix it?


I'm having the same problem. Programatically created accordion panes do not collapse. Can anyone please help?


Hi,

Here is a sample made as your description, it works fine. Please try it:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { //TextBox tb = new TextBox(); //MyAccordion.HeaderSelectedCssClass = ""; //AccordionPane1.HeaderContainer.Controls.Add(tb); AccordionPane ap = new AccordionPane(); MyAccordion.Panes.Add(ap); LinkButton lb = new LinkButton(); lb.Text = "hello"; ap.HeaderContainer.Controls.Add(lb); TextBox tb2 = new TextBox(); ap.ContentContainer.Controls.Add(tb2); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <ajaxToolkit:Accordion ID="MyAccordion" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" FadeTransitions="false" FramesPerSecond="40" TransitionDuration="250" AutoSize="None" RequireOpenedPane="false" SuppressHeaderPostbacks="true"> <Panes> <ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server"> <Header><a href="http://links.10026.com/?link=">1. Accordion</a></Header> <Content> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Button" /> The Accordion is a web control that allows you to provide multiple panes and display them one at a time. It is like having several where only one can be expanded at a time. The Accordion is implemented as a web control that contains AccordionPane web controls. Each AccordionPane control has a template for its Header and its Content. We keep track of the selected pane so it stays visible across postbacks. </Content> </ajaxToolkit:AccordionPane> <ajaxToolkit:AccordionPane ID="AccordionPane2" runat="server"> <Header><a href="http://links.10026.com/?link=">2. AutoSize</a></Header> <Content> <p>It also supports three AutoSize modes so it can fit in a variety of layouts.</p> <ul> <li><b>None</b> - The Accordion grows/shrinks without restriction. This can cause other elements on your page to move up and down with it.</li> <li><b>Limit</b> - The Accordion never grows larger than the value specified by its Height property. This will cause the content to scroll if it is too large to be displayed.</li> <li><b>Fill</b> - The Accordion always stays the exact same size as its Height property. This will cause the content to be expanded or shrunk if it isn't the right size.</li> </ul> <asp:Button ID="Button2" runat="server" Text="Button" /> </Content> </ajaxToolkit:AccordionPane> <ajaxToolkit:AccordionPane ID="AccordionPane3" runat="server"> <Header><a href="http://links.10026.com/?link=">3. Control or Extender</a></Header> <Content> The Accordion is written using an extender like most of the other extenders in the AJAX Control Toolkit. The extender expects its input in a very specific hierarchy of container elements (like divs), so the Accordion and AccordionPane web controls are used to generate the expected input for the extender. The extender can also be used on its own if you provide it appropriate input. </Content> </ajaxToolkit:AccordionPane> </Panes> </ajaxToolkit:Accordion> </div> <script type="text/javascript"> function pageLoad(sender, args) { var behavior = $find('MyAccordion_AccordionExtender'); behavior.add_selectedIndexChanged(onSelectedIndexChanged); } function onSelectedIndexChanged(sender, args) { } </script> </form></body></html>
Hope this helps.

I have solved my problem by changing mypane.controls.add() to mypane.contentcontainer.add().

Dynacly add scriptmanager when needed?

Hi,

I'm trying to create a Web User Control that uses asp.net Ajax. I'd like it to find out if a scriptmanager already exists in the page and, if not, add ti dynamically. Would such a thing be possible?


Thanks in advance for any help.


Regards,

Stefan

Yes its possible, you can check if ScriptManager is registered. FindControl(); or you can added it in the Master Page

http://forums.asp.net/thread/1441992.aspx

http://forums.asp.net/thread/1436775.aspx


Thanks for your quick reply. But how would I use FindControl if I don't know what the name of the scriptmanager would be?

I'm thinking of a situation where my control gets used in combination with other ajax controls, or gets used multpile times on a form. (Actually, my control would be a DotNetNuke module)

Any ideas?


If you didn't change it ScriptManager1


I know, but the hard thing is, that all controls get added to the page dynamically by DotNetNuke. This means I'm pretty sure the name won't be ScriptManager1...

So if there's no other way than to use findcontrol, the only option would be to add the ScripManager to the page itself somehow.


Thanks for your help.



hello.

you can get a reference to the ScriptManager control by using the static GetCurret method. If there's already a ScriptManager on the page, you will get a non null value.

I've put together an example ofUsing Control Adapters to automatically attach AJAX Extenders to ASP.NET Controls, which isn't exactly what you want, but there is code for walking through the controls on a page to see if there is already a ScriptManager or ScriptManagerProxy ...

http://damianblog.com/2006/11/16/adapters-and-extenders/

Damian


hello.

hum...why are you going through a cicle to get the scriptmanager control?


Because I'm doing it from an HttpModule ... and also because I didn't know of the static method :-)

Not sure if it will work in the module though ... will have a go.

Damian


hello.

well, i guess it might not work if you haven't instantiated the master page (which is easily solved by just "touching" the property)


Hi again, it's been a while since I had time to figure this thing out, but your answers look promising. Thanks a lot so far.

Dyanmically created linkbuttons, within UpdatePanel, is not working

Hello Folks,

I am updating a placeholder, to create some form controls, from my code behind.

I am successful. Now, I want to create a linkbutton, next to each form control i create, that when clicked on, go to the same generic event and read the control's ID (passed by the linkbutton somehow) and then I will do the logic to remove the control from the placeholder. Right now it creates the linkbuttons, but to ensure i don't have duplicate ID's, I add a unique int.tostring on the end of the ID of the linkbuttons. And I added the handler that should send all clicks, from all the linkbuttons to the same event. But I put a breakpoint in that event and when I click any of the linkbuttons, it just refreshes and no change to the page and the breakpoint in the event is never reached. Please let me know if you have any ideas, questions.. a portion of my code, with notes, below...

I am able to create all form elements except buttons, link buttons, etc.

I think the link button creation should be as simple as:

victorylinkBTN.ID ="victorylinkBTN" & VictoryReplicantCount.ToString

AddHandler victorylinkBTN.Click,AddressOf victorylinkBTN_Click

DCP.Controls.Add(victorylinkBTN)

victorylinkBTN.Text ="Del"

Dim vicEventAsNew System.EventArgs()

Is that right? It does create the linkbuttons, but the click fails. It submits, but nothing happens, it just refreshes with nothing changed, and doesn't land on my breakpoint, in the sub below.

Sub victorylinkBTN_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)

Dim linkbutAs LinkButton =CType(sender, LinkButton)

Dim linkbutIDAsString = linkbut.ID.ToString

'do more work……

EndSub

If you have any idea what I am doing wrong, please let me know.

Also, if you have experience with update panels, if I make the update panel conditional, then how would I set each of these linkbuttons to have trigger rights to the related update panel?

Again, thanks for any help ...

Folks,

I have found a cheesy way to do this, by adding javascript on each linkButton created that inserts the linkButton ID into a hidden field's value on the page and then on that linkButton submit, in pageLoad, I read the value of the hidden field to decide to perform the action.

This works, and would take some serious time to explain. Please feel free to email me via the forum contact ability, if you want details.

I am leaving this open, hoping someone in the asp.net team will have a better solution.


Since you dynamically add thelink buttons, you should add it to the PlaceHolder in the Page_Load event every time instead of adding it just the page first load. Because when you only add it the first time the page load, after post back, thelink buttonswill disappear. And itdoesn't land on your breakpoint invictorylinkBTN_Click,There is non victorylinkBTN when your postback.

Try this:

publicpartialclassDefault2 : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

AddControl(PlaceHolder_ContentRight,"~/WebUserControl.ascx",true);

}

privatevoid AddControl(PlaceHolder PlaceHolder,string ControlPath,bool Clear)

{

Control Control_ToAdd;

Control_ToAdd = LoadControl(ControlPath);

if (Clear)

{

PlaceHolder.Controls.Clear();

}

PlaceHolder.Controls.Add(Control_ToAdd);

}

}

If this help you,don't forget mark it as a answer.Thanks!

Best Regards

Jin-Yu Yin

dyanamic creation of toolkit controls?

Hi,

Can we create ajax controls dynamically i.e. in javascript? For example, I wish to create a tab control dynamically? Can we do that?

--jon

You can definitely create your AJAX controls/behaviors using the $create() statements (most likely called/hooked-up from the application init function). You should create a few Ajax controls declaratively in the page and then view the source it outputs to get an idea of the syntax needed.

Duplicate Script Reference

I am trying to create a WebControl dll. There is a common.js file in the dll. It is shared bewteen all WebControls.

If I simply add the script reference using
ScriptManager.Scripts.Add( ...) or implementingGetScriptReferences function of IScriptControl. Duplicate script reference will be created when user add multiple web controls.

It is a problem because a ajax javascript class cannot be registered twice.

If I use ScriptManager.RegisterClientScriptInclude, the script will be unique but it is inserted before ajax javascript liberary.

It seems that I have to do something special to make this work. anyone has suggestions or has experienced the same issue??

thanks

Rushui

Look up the example under ajax.asp.net/docs for the IScriptControl interface. If you implement the interface using their example as a template you shouldn't have issues; I'm not sure what they're doing under the hood, but the GetScriptReferences method specified is being called in some way that helps avoid conflicts.

Upon further investigation, it seems that duplicate script reference of a web control dll can be avoided by implementing GetScriptReference function of IScriptControl interface. The Scripts collection of ScriptManager however doesnot check for duplicates.

My situation is a bit strange since I am trying to share a common js lib between the page and the web control dll. Guess I just have to avoid doing that.

Thanks

Rushui

Saturday, March 24, 2012

DropShadow Extender: Opacity-property problem

I create Atlas-website, put ScriptManager on top of the page, add panel and set height, width and background-color properties. Then i add AtlasToolkit Dropdown Extender on the page ja set it's properties. My problem is that the dropshadow is only visible when Opacity is set to 1.0. If I set Opacity-property to less than 1.0 eg. 0.75, Panel-control doesn't show drop shadow. Am I missing something?

DropShadow-sample page works though..

Which browser are you using? But you're saying the sample is working okay, so I'm not sure what's wrong. If opacity is 1.0, the extender doesn't bother to apply the OpacityBehavior, which manages the opacity property. It would be interesting to see if the OpacityBehavior works on your panel. Maybe take a closer look at any differences between the sample and your page?


I'm using IE6 & IE7.

This markup with opacity set to .7 doesn't show dropshadow for panel:

<%@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"%>

<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit"%>

<!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>mySample Page</title>

<styletype="text/css">

.panelStyle {

width:350px;

height:250px;

background:#517dbf;

}

</style>

</head>

<body>

<formid="form1"runat="server">

<atlas:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:PanelID="Panel1"runat="server"CssClass="panelStyle">

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server">

<atlasToolkit:DropShadowProperties

TargetControlID="Panel1"

Width="5"

Opacity=".75"

TrackPosition="true"

Rounded="false"/>

</atlasToolkit:DropShadowExtender>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

But when I add the checboxlist w/ onclick-events from the samplepage , dropshadow is visible when checkbox is checked: now opacity values from .25 to .75 are working ok.

On DesignView DropShadowExtender1-Control displays error-text: 'TargetProperties' could not be initialized. Details: 'TargetProperties' could not be added to the collection. Details: 'dsBehavior' could not be set on property 'ID'. Doesn't throw any run-time errors.

<%@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"%>

<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit"%>

<!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>mySample Page</title>

<styletype="text/css">

.panelStyle {

width:350px;

height:250px;

background:#517dbf;

}

</style>

</head>

<body>

<formid="form1"runat="server">

<atlas:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:PanelID="Panel1"runat="server"CssClass="panelStyle">

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server">

<atlasToolkit:DropShadowProperties

ID="dsBehavior"

Opacity=".75"

Rounded="false"

TargetControlID="Panel1"

TrackPosition="true"

Width="5"/>

</atlasToolkit:DropShadowExtender>

</div>

<divstyle="padding: 15px;">

<labelfor="chkShadow">

Show Drop Shadow:

</label>

<inputid="chkShadow"checked="checked"onclick="var b = $object('dsBehavior'); b.set_Width(chkShadow.checked ? 5 : 0);"

type="checkbox"/><br/>

<labelfor="chkRounded">

Rounded:

</label>

<inputid="chkRounded"checked="checked"onclick="var b = $object('dsBehavior'); b.set_Rounded(chkRounded.checked);"

type="checkbox"/>

<div>

Opacity:

<inputid="opacity25"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".25"/><labelfor="opacity25">25%</label>

<inputid="opacity50"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".5"/><labelfor="opacity50">50%</label>

<inputid="opacity75"checked="checked"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".75"/><labelfor="opacity75">75%</label>

<inputid="opacity100"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value="1.0"/><labelfor="opacity100">100%</label>

</div>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>


My best guess is that this has something to do with your video card/driver. I'm not sure how IE (or FireFox) does opacity but your first sample works fine for me for all Opacity values. Note I also do not get the design time errors you're mentioning, but that shouldn't affect the runtime behavior. Does it work in other browsers for you?

I've tried with FF & IE and two different laptops with same results (both laptops have VS 2005 Team Developer installed). I don't think it's video card/driver 'cause SamplePage's checkboxlist w/ onclick-events works ok. (BTW i have NVIDIA FX 1400 Go 256Mt-video card.) DesignView error happens when I add ID-property for the DropShadowProperties. Error disappears when I remove ID-property.

IntelliSense shows only "Opacity, Rounded, TargetControlID, TrackPosition and Width"-properties, no Id-property? I uninstalled and reinstalled all Atlas relatud stuff and created a new Atlas-website, but no dropshadow with opacity less than 1.0.

I'll keep digging.. or just use CSS-based dropshadows..Sad [:(]


This markup displays default dropshadow with opacity 1.0:

<

atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/><div>
<asp:PanelID="Panel1"CssClass="panelStyle"runat="server"></asp:Panel>
<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server"EnableViewState="true">
<atlasToolkit:DropShadowPropertiesTargetControlID="Panel1"/>
</atlasToolkit:DropShadowExtender>
</div>

BTW) Why tagprefix is cc1 and not atlasToolkit (you have to manually change it)

From the DropShadowProperties.cs:

// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// Seehttp://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.


using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using Microsoft.AtlasControlExtender;

namespace AtlasControlToolkit
{
public class DropShadowProperties : TargetControlPropertiesBase<Panel>
{

/// <summary>
/// The opacity of the shadow, from 0 (transparent - no shadow rendered) to 1.0, which is fully opaque black.
///The default is .5.
/// </summary>
[DefaultValue(1.0f)]<-- This is not default .5
public float Opacity
{
get
{
return GetPropertyValue<float>("Opacity", 1.0f);<-- This is not default .5
}
set
{
SetPropertyValue<float>("Opacity", value);
}
}


Yes, that's a documentation bug, thanks for pointing it out.

The tag prefixes are arbitrary. They default to "cc1" or whatever, there isn't any way to specify them automatically.

Thanks!


Oh - the ID field is marked Browsable(false) so it won't show up in intellisense.

It's not needed in the 90% case and you can get yourself in trouble (e.g. if you use it in a repeater) so it's hidden.

DropDownList1.SelectedValue allways the same on postbacks

Hi,

I'm new to Atlas/Ajax, so please forgive if this is a simple question.

I'm trying to create a simple solution, where I databinds a DropDownList and when the SelectedValue changes, a GridView must reflect the new data.

My problem is, when making the Ajax callback, the DropDownList.SelectedValue is always the same no matter what item is selected ind the DropDownList. Somehow the server does not know the new value.

Here's my code...

<formid="form1"runat="server">
<atlas:ScriptManagerID="ScriptManager1"EnablePartialRendering="true"runat="server"/>
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"/>
<div>
<atlas:UpdatePanelID="aup"runat="server">
<ContentTemplate>
<asp:GridViewID="GridView1"runat="server"/>
</ContentTemplate>
<Triggers>
<atlas:ControlValueTriggerControlID="DropDownList1"PropertyName="SelectedValue"/>
</Triggers>
</atlas:UpdatePanel>
</div>
</form>

Here's my code behind...

Imports

System.Data

Partial

Class _Default
Inherits System.Web.UI.PageProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
Call GetDropDownItems()
EndSubProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged
Call GetData()
EndSubPrivateSub GetDropDownItems()
Dim dtAs DataTable = .. get my DropDownList items as datatable
Me.DropDownList1.DataSource = dt
Me.DropDownList1.DataTextField ="text"
Me.DropDownList1.DataValueField ="ID"
Me.DropDownList1.DataBind()
EndSubPrivateSub GetData()
Dim dtAs DataTable = ... get data depending on theDropDownList1.SelectedValue <-- this is always the same!!
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
EndSub

End

Class

Hope you can help me out here.

Thanks!

M O J O

Sorry ... I found out the problem.

I just had to do this instead...

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
If Not Page.IsPostBack Then
Call GetDropDownItems()
End If
EndSub

Thanks anyway!!!

M O J O


Hi: Mojo

I had same problem, thank you for the hint.

Do you think why it happened, why Postback is important. Although it works, but I need to know why?

Will be great that you can give my some idea.

Thanks.

James


The reason is,

Whenever a DropDownList is databound, the SelectedValue is always cleared out. To prevent the users selection from getting cleared out, you would only databind the DDL on the first hit to the page (when it's not a PostBack). Then on subsequent PostBacks, you would not databind your DDL. The ListItems in the DDL will get restored to the control from ViewState and the users selection (as read from the forms Post data) will get set on the DDL control.


thanks, mbanavige, now i c

James

Dropdownlist with non-selectable ListItems

Is it possible to use one of the toolkit controls to create a Dropdownlist containing ListItems that are selectable andnon-selectable? (i.e. hovering your mouse over thenon-selectable items doesn't highlight them and clicking on them does nothing - they are just there to group ListItems together).

Consider these 8 ListItems in a DropdownList:

-- Fruit --

Apple

Orange

Banana

-- Vegetables --

Carrot

Onion

Garlic

Using this hypothetical control, the ListItems "--Fruit--" and "--Vegetables--" would benon-selectable (and just there for grouping). All other listitems would be selectable.

How can I do this?

Hi,

Currently, this feature isn't available, you may submit a feature requesthere if you don't plan to implement it yourself.

Wednesday, March 21, 2012

DropDownExtender question

Can I use the DropDownExtender to create a google suggest textbox? If not, is there another control i can use to do this, or do I have to build my own?

Thanks

sorry...what is google suggest textbox

http://www.google.com/webhp?complete=1&hl=en

The AutoCompleteExtender does what I want but I'm not sure how to send the textbox value to the webservice to sort the dataset. Here's my code...

 <asp:TextBox ID="txtTest" runat=server></asp:TextBox> <asp:AutoCompleteExtender ID=ace1 runat=server TargetControlID="txtTest" ServicePath="WebService.asmx" ServiceMethod="getZoneSuggestions" MinimumPrefixLength="1" />
[ScriptMethod] [WebMethod(EnableSession =true)]public string[] getZoneSuggestions(string test) {string[] result; result =new string[4]; result[0] ="atest1"; result[1] ="atest2"; result[2] ="btest2"; result[3] ="btest2";return result; }
When I try to pass the string into getZoneSuggestions nothing happens, but when I remove "string test" it will show all of my results.
 

I figured it out.

[ScriptMethod] [WebMethod(EnableSession =true)]public string[] getZoneSuggestions(String prefixText,int count) {string[] result; result =new string[4]; result[0] ="atest1"; result[1] ="atest2"; result[2] ="btest2"; result[3] ="btest2";return result; }