Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

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 Control TextBox values not refreshed with example code

Ok, here is my situation. I have a dynamic TextBox that is added to the UpdatePanel. I need to be able to set the value of that textbox on the UpdatePanel refresh. I'm able to do that with Label control but not with the TextBox. Is that a known issue, is there a workaround? I assume i can use the standard input control possibly, but due to my project i have to use pre existing set of user controls which use TextBox. Any help is appriciated. The code is included below:

Short explanation of the example:

Example provides a link to refresh the UpdatePanel. On refresh two controls are added to the collection with specified value which is the Current time. One control is textbox and the other one is label. If you keep hitting refresh the value of the Label is changed while the value of the TextBox remains the same. Example output:test //5/11/2007 1:57:52 PM

Thanks!

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><script runat="server"> protected void Page_Load(object sender, EventArgs e) { TextBox textBox = new TextBox(); textBox.Text = DateTime.Now.ToString(); Label label = new Label(); label.Text = DateTime.Now.ToString(); test.Controls.Clear(); test.Controls.Add(textBox); test.Controls.Add(label); }</script><script type="text/javascript"> function UpdateDialogControl(val) { var ctrl = $get('<%=DialogTrigger.ClientID%>'); ctrl.value = val; __doPostBack('<%=DialogTrigger.UniqueID%>',''); }</script><body> <form id="form1" runat="server"> <a href="javascript:UpdateDialogControl(1)">test</a> <asp:HiddenField runat="server" ID="DialogTrigger" /> <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" /> <asp:UpdatePanel UpdateMode="Conditional" ID="CenterContentPanel" runat="server" RenderMode="Inline"> <Triggers> <asp:AsyncPostBackTrigger ControlID="DialogTrigger" /> </Triggers> <ContentTemplate> <asp:PlaceHolder runat="server" ID="test"></asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

In Page_Load Event, Put all the statement into the !IsPostBack block.

if (!IsPostBack)
{
//all the code
}


Okay ... the controls are not displayed at all on the refresh.

Textbox's update their value based on the posted value from the previous request. So you're adding it, then its getting updated, overwriting your set value. Disabling ViewState will not affect this, since the value comes from the posted values collection, not viewstate.

Normally TextBox's are updated by the time you get to OnLoad, but since this TextBox didn't exist at that time, it isn't updated until AFTER OnLoad.

So -- heres what you do...

Add the TextBox in OnInit instead. Then in OnLoad, you can set the value to whatever you want, knowing full well that the posted value has already been loaded.

I recommend you follow the link to my blog and read about dynamic controls :)


Hi, thanks for the answer. However ... I do understand how ViewState works and that you need to add controls dynamically during or before OnInit event in order for them to keep track of viewstate. Your solution will indeed work for that specific example. I need an ability to remove all the controls and add completely new ones on refresh with values i specified.

Actually this specific problem is not related to ViewState at all. Its the POST state of the textbox that is in question here. Even if you turned off viewstate to the entire page this same solution would apply. Dynamically added controls can keep track of their own viewstate no matter when you add them to the tree (as long as its before SaveViewState, which is between PreRender and Render).

If what you want is to destroy all the existing controls and start with fresh ones, its ok to clear to the control tree and start a new one -- but you have to give the existing controls a chance to load their prior state first, so that they "consume" that data. So you would do this in Load, or in response to an event (like a click event, which would be raised after Load).


So you are saying i have to add old controls before load event then in OnLoad even clear the controls collection and add new elements with a values i specified? (in the example above i'm adding controls in the Onload event).

BTW, I did not have the same problem without UpdatePanel it seems like it is adding extra remember state feature ...

Thanks for replies btw.


Nm, UpdatePanel does behave like any other control. It is not related to any extra remember state feature ... I guess i never encountered problem when i needed to completely refresh controls and yes you are right I did it on the SelectedIndex changed event before which worked fine. Now i need to do it on UpdatePanel refresh and this is where i'm having issues.

Thanks for the post again. I indeed needed to rebind the form on the event. So in case of UpdatePanel it was the ValueChanged event for the hidden input control. Just like you told the viewstate is restored when form is bound on OnLoad event and then when i bind it second time i can put new values for the controls.

Thanks!

Dynamic AutoCompleteExtenders -- 0 Requests Made

I'm dynamically creating a set of textboxes with autocompleteextenders, but something's not going quite right. Here's the code:

FilterList.Controls.Clear(); Table FiltersTable =new Table(); FilterList.Controls.Add(FiltersTable);foreach (string Filterin _Columns) { TableRow FilterRow =new TableRow(); TableCell LabelCell =new TableCell(); Label ColumnName =new Label(); ColumnName.Text = Filter +":"; LabelCell.Controls.Add(ColumnName); TableCell TextCell =new TableCell(); TextBox ColumnText =new TextBox(); ColumnText.ID = Filter +"Box"; ColumnText.Width = 100; ColumnText.CssClass = Filter; TextCell.Controls.Add(ColumnText); AjaxControlToolkit.AutoCompleteExtender Extender =new AjaxControlToolkit.AutoCompleteExtender(); Extender.ID = Filter +"Extender"; Extender.TargetControlID = ColumnText.ID; Extender.ServicePath ="GetAutoCompleteItems.asmx"; Extender.ServiceMethod ="GetCompletionList"; Extender.MinimumPrefixLength = 2; Extender.CompletionInterval = 500; Extender.CompletionSetCount = 10; Extender.ContextKey = Filter; TextCell.Controls.Add(Extender); FilterRow.Cells.Add(LabelCell); FilterRow.Cells.Add(TextCell); FiltersTable.Rows.Add(FilterRow); }

I brought up Firefox/Firebug and watched the network requests. I'd clear out the list of current requests so it was completely empty. As soon as I typed 2 characters into one of the textboxes, firebug would pop up "0 requests". And of course my web service is never hit.

Any ideas on what I might be doing wrong?

I'm still trying to figure this out. Has anyone had any success dynamically adding AutoCompleteExtenders to a page?

Edit: After more searching, it appears the answer fromthis page works.

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

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

DummyHtmlTextWriter Exception

Hi All,

I am getting the following exception using the April CTP:

System.Exception was unhandled by user code Message="An instance of 'Microsoft.Web.UI.DummyHtmlTextWriter' could not be used as an HtmlTextWriter. Make sure the specified class can be instantiated, extends System.Web.UI.HtmlTextWriter, and implements a constructor with a single parameter of type System.IO.TextWriter." Source="App_Web_sqmaviya" StackTrace: at Forms_Coordinators_AwardPoints.scriptManager_PageError(Object sender, PageErrorEventArgs e)in c:\Documents and Settings\jyoung\My Documents\Visual Studio 2005\WebSites\Pointfolio_v2\Forms\Coordinators\AwardPoints.aspx.cs:line 188 at Microsoft.Web.UI.ScriptManager.OnPageError(PageErrorEventArgs e) at Microsoft.Web.UI.ScriptManager.OnPageError(Exception ex) at Microsoft.Web.UI.ScriptManager.RenderPageCallback(HtmlTextWriter writer, Control pageControl) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
This has proven to be very difficult to replicate as it seems completely random.
I have a web user control that contains a TreeView and 2 GridViews (available and selected).
Think file explorer with folders in the tree, files in one gridview and files that have been selected (via available) in the second gridview.
Both gridviews are wrapped in updatepanels with available triggering off the treeview and the selected triggering off the command of available.
The above exception gets thrown at random points when the triggers are fired.
I say random, because I can replicate the error, but not in an orderly fashion.
I go through selecting and deselecting and everything works fine and then boom exception.
Any help or insight would be greatly appreciated.

I tried the June CTP with the same issues.


In the hopes that this was an issue with the local dev server that is built into VS, I tried this under IIS6 with the same exception.

I am growing very discouraged by this. I ditched a custom built AJAX implementation in favor of Atlas and am now thinking that I have to ditch Atlas and go back to my implementation. I REALLY REALLY don't want to do this, but I don't know how to get around the exception.

I tried swallowing the exception but then I can an "Unknown Error" alert and then the whole thing blows up.

The aspx markup and codebehind is a bit long, but I can post it if you think it will help.

If this is an exception that I can do nothing about, is there anyway to swallow it and have it keep working without having to refresh the page?

I could really use the help on this one.

Thanks,

Joe


Hi,

two questions:

1) are you handling the PageError event of the ScriptManager?
2) are you using cache?

Hi, I am using the PageErrorEvent

protected void scriptManager_PageError(object sender, Microsoft.Web.UI.PageErrorEventArgs e) {throw new Exception(e.ErrorMessage); }
There is no caching at this page. There is some cache use in other parts of the application.

I take it there is some issue between Atlas and Output Caching and if we use one we can't use the other? What are the issues? Can you point me to a resource where there is more information?


I created a test project and was able to replicate the error.
It seems to have to due something with output caching. I added a webusercontrol and enabled output caching on it and got the error.
I can't upload my test solution so I will show all the code.

Web.Config
<configuration>
<!--
The configSections define a section for ASP.NET Atlas.
-->
<configSections>
<sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
<section name="converters" type="Microsoft.Web.Configuration.ConvertersSection" />
<section name="webServices" type="Microsoft.Web.Configuration.WebServicesSection" />
<section name="authenticationService" type="Microsoft.Web.Configuration.AuthenticationServiceSection" />
<section name="profileService" type="Microsoft.Web.Configuration.ProfileServiceSection" />
</sectionGroup>
</configSections
<!--
The microsoft.web section defines items required for the Atlas framework.
-->
<microsoft.web>
<converters>
<add type="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>
<add type="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>
<add type="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>
</converters>
<webServices enableBrowserAccess="true" />
</microsoft.web>

<appSettings/>
<connectionStrings/>

<system.web>
<pages>
<controls>
<add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
<add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
</controls>
</pages>
<compilation debug="false">
<buildProviders>
<add extension=".asbx" type="Microsoft.Web.Services.BridgeBuildProvider" />
</buildProviders>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
<!--
The MultiRequestHandler enables multiple requests to be handled in one
roundtrip to the server. Its use requires Full Trust.
-->
<add verb="*" path="atlasbatchcall.axd" type="Microsoft.Web.Services.MultiRequestHandler" validate="false"/>
<add verb="*" path="atlasglob.axd" type="Microsoft.Web.Globalization.GlobalizationHandler" validate="false"/>
<!--
The IFrameHandler enables a limited form of cross-domain calls to 'Atlas' web services.
This should only be enabled if you need this functionality and you're willing to expose
the data publicly on the Internet.
To use it, you will also need to add the attribute [WebOperation(true, ResponseFormatMode.Json, true)]
on the methods that you want to be called cross-domain.
This attribute is by default on any DataService's GetData method.

<add verb="*" path="iframecall.axd" type="Microsoft.Web.Services.IFrameHandler" validate="false"/>
-->
<add verb="*" path="*.asbx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>
<add name="BridgeModule" type="Microsoft.Web.Services.BridgeModule"/>
<add name="WebResourceCompression" type="Microsoft.Web.Services.WebResourceCompressionModule"/>
</httpModules>
<authentication mode="Windows" />
</system.web>
</configuration>

ASPX Page
<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AtlasTest._Default" %
<%@. register src="http://pics.10026.com/?src=WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<atlas:scriptmanager id="scriptManager" runat="server" enablepartialrendering="true" onpageerror="scriptManager_PageError"></atlas:scriptmanager>
<asp:treeview id="TreeView1" runat="server" onselectednodechanged="TreeView1_SelectedNodeChanged">
</asp:treeview>
<atlas:updatepanel id="updatePanel1" runat="server" mode="Conditional">
<contenttemplate>
<asp:gridview id="GridView1" runat="server" backcolor="White" bordercolor="#CC9966" borderstyle="None" borderwidth="1px" cellpadding="4" autogeneratecolumns="False" autogenerateselectbutton="True" onselectedindexchanged="GridView1_SelectedIndexChanged">
<footerstyle backcolor="#FFFFCC" forecolor="#330099" />
<rowstyle backcolor="White" forecolor="#330099" />
<selectedrowstyle backcolor="#FFCC66" font-bold="True" forecolor="#663399" />
<pagerstyle backcolor="#FFFFCC" forecolor="#330099" horizontalalign="Center" />
<headerstyle backcolor="#990000" font-bold="True" forecolor="#FFFFCC" />
<columns>
<asp:boundfield headertext="Id" datafield="Id" />
<asp:boundfield headertext="Name" datafield="Name" />
</columns>
</asp:gridview>
</contenttemplate>
<triggers>
<atlas:controleventtrigger controlid="TreeView1" eventname="SelectedNodeChanged" /></triggers>
</atlas:updatepanel>
</div>
<uc1:webusercontrol1 id="WebUserControl1_1" runat="server" />
</form>
</body>
</html>

Code Behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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;

namespace AtlasTest
{
public partialclass _Default : System.Web.UI.Page
{
private Dictionary<int, Group> groupDictionary;

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

if (!Page.IsPostBack)
{
BindGroupTree(groupDictionary[1],null);
}
}

private void CreateGroups()
{

groupDictionary =new Dictionary<int, Group>();

Group root =new Group(1,"Root");
Group child1 =new Group(2,"Child1");
Group child2 =new Group(3,"Child2");
Group child11 =new Group(4,"Child11");
Group child12 =new Group(5,"Child12");
Group child21 =new Group(6,"Child21");
Group child22 =new Group(7,"Child22");

groupDictionary.Add(root.Id, root);
groupDictionary.Add(child1.Id, child1);
groupDictionary.Add(child2.Id, child2);
groupDictionary.Add(child11.Id, child11);
groupDictionary.Add(child12.Id, child12);
groupDictionary.Add(child21.Id, child21);
groupDictionary.Add(child22.Id, child22);

// Build the tree
root.Children.Add(child1.Id, child1);
root.Children.Add(child2.Id, child2);

child1.Children.Add(child11.Id, child11);
child1.Children.Add(child12.Id, child12);

child2.Children.Add(child21.Id, child21);
child2.Children.Add(child22.Id, child22);

child1.Users.Add(new User(11,"Test 11"));
child1.Users.Add(new User(12,"Test 12"));
child1.Users.Add(new User(13,"Test 13"));
child1.Users.Add(new User(14,"Test 14"));
child1.Users.Add(new User(15,"Test 15"));

child2.Users.Add(new User(21,"Test 21"));
child2.Users.Add(new User(22,"Test 22"));
child2.Users.Add(new User(23,"Test 23"));
child2.Users.Add(new User(24,"Test 24"));
child2.Users.Add(new User(25,"Test 25"));

child11.Users.Add(new User(111,"Test 111"));
child11.Users.Add(new User(112,"Test 112"));
child11.Users.Add(new User(113,"Test 113"));
child11.Users.Add(new User(114,"Test 114"));
child11.Users.Add(new User(115,"Test 115"));

child12.Users.Add(new User(121,"Test 121"));
child12.Users.Add(new User(122,"Test 122"));
child12.Users.Add(new User(123,"Test 123"));
child12.Users.Add(new User(124,"Test 124"));
child12.Users.Add(new User(125,"Test 125"));

child21.Users.Add(new User(211,"Test 211"));
child21.Users.Add(new User(212,"Test 212"));
child21.Users.Add(new User(213,"Test 213"));
child21.Users.Add(new User(214,"Test 214"));
child21.Users.Add(new User(215,"Test 215"));

child22.Users.Add(new User(221,"Test 221"));
child22.Users.Add(new User(222,"Test 222"));
child22.Users.Add(new User(223,"Test 223"));
child22.Users.Add(new User(224,"Test 224"));
child22.Users.Add(new User(225,"Test 225"));
}

private void BindGroupTree(Group group, TreeNode parent)
{
if (group.Children ==null) {return; }

foreach (KeyValuePair<int, Group> kvpin group.Children)
{
TreeNode treeNode =new TreeNode();
treeNode.Value = kvp.Key.ToString();
treeNode.Text = kvp.Value.Name;

if (parent ==null)
{
TreeView1.Nodes.Add(treeNode);
}
else
{
parent.ChildNodes.Add(treeNode);
}

BindGroupTree(kvp.Value, treeNode);
}
}

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
int selectedIndex = System.Convert.ToInt32(TreeView1.SelectedValue);

List users = groupDictionary[selectedIndex].Users;

GridView1.DataSource = users;
GridView1.DataBind();
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void scriptManager_PageError(object sender, Microsoft.Web.UI.PageErrorEventArgs e)
{
throw new Exception(e.ErrorMessage);
}
}
}

Data
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
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;

namespace AtlasTest
{
public class Group
{
private int id;
private string name;
private Dictionary<int, Group> children;
private List users;

public int Id
{
get {return this.id; }
set {this.id =value; }
}

public string Name
{
get {return this.name; }
set {this.name =value; }
}

public Dictionary<int, Group> Children
{
get {return this.children; }
}

public List Users
{
get {return this.users; }
}

public Group(int id,string name)
{
this.id = id;
this.name = name;
this.children =new Dictionary<int, Group>();
this.users =new List();
}
}

public class User
{
private int id;
private string name;

public int Id
{
get {return this.id; }
set {this.id =value; }
}

public string Name
{
get {return this.name; }
set {this.name =value; }
}

public User(int id,string name)
{
this.id = id;
this.name = name;
}
}
}

WebUserControl
<%@. Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="AtlasTest.WebUserControl1" %>
<%@. outputcache duration="5" varybyparam="none" %>
<asp:datalist id="DataList1" runat="server" onitemdatabound="DataList1_ItemDataBound">
<itemtemplate>
<asp:label id="lblTest" runat="server" text="Label"></asp:label>
</itemtemplate>
</asp:datalist>

WebUserControl CodeBehind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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;

namespace AtlasTest
{
public partialclass WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}

private void BindData()
{
List<string> testList =new List<string>();
testList.Add("One");
testList.Add("Two");
testList.Add("Three");
testList.Add("Four");
testList.Add("Five");

DataList1.DataSource = testList;
DataList1.DataBind();
}

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
string test = e.Item.DataItemas string;

Label lblTest = e.Item.FindControl("lblTest")as Label;

lblTest.Text = test;
}
}
}
}

It seems like there are some severe issues with Atlas and Caching. Is the Atlas team aware of this? If so is there a fix coming soon or a work around?

Thanks,

Joe


Hi,

is there any user control with cache enabled, in your page? What I suggest is, if you have user controls in your page, to remove each one and see if the problem persists. Specifically, look for controls or user controls that are *outside* an UpdatePanel.

Yeah, there was one usercontrol that used cache. It happens to be the only place where caching is used. I disabled the cache and have yet to encounter the exception. Is there a way to use both atlas and caching that I am not aware of? Is this behavior expected to be fixed in the final release. I will keep caching disabled for the time being as we cannot have random exceptions being thrown about,Big Smile but I would really like to use both.

Joe


Hi,

yes, there is an issue with the UpdatePanel and Output caching, at least in the April CTP:

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

I don't know if it has been fixed in the current CTP (June), you can try to switch to the June CTP and see if it works, otherwise I'll do a test later. Let me know how it goes.

Thanks for the post about the issue, i have been looking everywhere (or so I thought) trying to find some more info.

I updated to the June CTP hoping that it was indeed fixed, but the same exception is still being thrown. I did not see error being fixed in the release notes as well, so I am assuming that it is not fixed. Hopefully it will be soon.Big Smile

Really appreciate the help and info.

Many Thanks,

Joe


I'm also encountering the same issue with the July CTP. I'm just hoping this will be fixed in whatever the next release is, as output caching is such a huge performance benefit.

Mark

Dual slider control in asp.net

I have downloaded the sample code fro Dual slider control from

Computer http://www.dimebrain.com/2007/11/another-dual-sl.html

it works well in normal scenario. if i apply inside a <td> tag inside a<table> tag The sample code doesnt work

any idea?

You have

<table>

<tr>

<td>...</td>

</tr>

</table>

right?

If you miss the <tr> element then you have a "little" problem.


I cant understand can u tell in detail.

I am using <table><tr><td>...... </td></tr></table> tag.


The solution is i have to adjust the style property of the particular div tag. I solved my previous problem.

Now an another one issue is, This slider doesnt support the Update control of atlas. Y? What s d solution?

dual Listbox

Any code out there hat uses ajax?

what is the exactly problem?

Please post the complete doubts waht you have ...


Hi, helixpoint

I am afraid we cannotfind out the exact root cause without further information captured when the problem occurs.

We are changing the issue state to "Resolved" because you have not followed up with the necessary information and we think that you have soloved it by yourself. If you have more time to look at the issue and provide more information, please feel free to change the issue state back to "Not Resolved". If the issue is really resolved by yourself, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Thank you!

DropShadowExtender with a Repeater

Hello all

Anyone know how I make this work.

I am trying to useDropShadowExtender with a Repeater.

I have tried.

When I have my DropShadowExtender code outside of my Repeater the DropShadowExtender can not find my panel.

When I put DropShadowExtender in the Repeater I get duplcate use of id error.

When use a DataBinder in the ID for the DropShadowExtender I getAtlasControlToolkit.DropShadowProperties does not have a DataBinding event.

You probably don't need an ID field in your DropShadowProperties declaration. If you've got one in there, just remove it, that should resolve the duplicate ID issue.

For the second issue, ASP.NET generally doesn't let you databind to non-control items, such as the DropShadowProperties class. You'll have to do this databinding in your DataBound event for the repeater. See an example of this at:

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

DropShadowExtender and SetFocus

Hi there,

I'm trying to set the focus to a textbox while using the DropShadowExtender, but it does not seem to work.

The code is something like this:

<asp:Panel id="panelContainer" runat="server">

<asp:Textbox id="txtName" runat="server" />

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="dseLogin"runat="server"><atlasToolkit:DropShadowPropertiesTargetControlID="panelContainer"Width="5"Rounded="true"Opacity=".75"TrackPosition="true"ID="dsBehavior"/></atlasToolkit:DropShadowExtender>

And in the code behind:

protectedvoid Page_Load(object sender,EventArgs e)

{

this.SetFocus(this.txtName);

}

What am I doing wrong? Is this a bug? Is there a workaround?

Thanks,

Rudy

Try searching this forum group (groupid:34) for SetFocus, I seem to recall seeing a post about this emitting code that couldn't be read correctly by Atlas. Maybe? I'm taking a stab but try to find the existing posts.
I did search for similar problems with SetFocus, but the posts I found were related to the TextBoxWatermarkExtender, not the DropShadowExtender.

This problem happens (I think) because the ASP.NET call to WebForm_AutoFocus (inserted by Page.SetFocus) happens before Atlas load. When Atlas loads and DropShadow initializes, it needs to mess around with the DOM and I think the manipulations it does end up losing the focus. My recommendation is to set the focus with the following instead as Application.load fires only AFTER Atlas and related code is finished initializing:

<script type="text/javascript">
Sys.Application.load.add(function() { $("txtName").focus(); });
</script>

The complete sample follows:

<%@. Page Language="C#" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="ScriptManager1" runat="Server"> </atlas:ScriptManager> <asp:Panel ID="panelContainer" runat="server"> <asp:TextBox ID="txtName" runat="server" /> </asp:Panel> <atlasToolkit:DropShadowExtender ID="dseLogin" runat="server"> <atlasToolkit:DropShadowProperties TargetControlID="panelContainer" Width="5" Rounded="true" Opacity=".75" TrackPosition="true" ID="dsBehavior" /> </atlasToolkit:DropShadowExtender> </div> </form> <script type="text/javascript"> Sys.Application.load.add(function() { $("txtName").focus(); }); </script></body></html>

Saturday, March 24, 2012

DropShadowExtender

I have a masterpage with the code below.

I have a Default.aspx page that uses the masterpage.

When Rounded is set to false then I get a panel with a shadow. If i changes Rounded to true, then I get two small areas (one white and one black). What am I doing wrong.

Best regards

S?ren Agerbo Jensen.

-------

MasterPage.master:

<%@dotnet.itags.org.MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inherits="MasterPage" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>FraIdeTilFaktura.dk</title>

</

head>

<

bodyalign="center"style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#EEEEEE', startColorstr='#555555', gradientType='0'); padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px;"><formid="form1"runat="server"style="text-align: center;"><div><tableborder="0"cellpadding="0"cellspacing="0"style="height: 600px; width: 80%;"><tr><tdstyle="width: 100%; height: 50px;"></td></tr><tr><tdid="tekst"style="width: 100%; height: 400px;"><asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager> <ajaxToolkit:DropShadowExtenderRounded="false"ID="DropShadowExtender1"runat="server"TargetControlID="Panel1"Radius="2"TrackPosition="true"Width="5"></ajaxToolkit:DropShadowExtender><asp:PanelID="Panel1"runat="server"Height="100%"Width="100%"BackColor="White"ScrollBars="Auto"><

<

asp:ContentPlaceHolderID="ContentPlaceHolder1"runat="server"></asp:ContentPlaceHolder></asp:Panel></td></tr><tr><tdstyle="width: 100%; height: 50px;"></td></tr></table></div></form>

</

body>

<

scripttype="text/javascript">

document.getElementById(

"tekst").style.height=screen.height-300;

</

script>

</

html>

Sorry for the trouble - pleaseopen a work item to report and track this issue. Thank you!

DropShadow Resize problem with the Shadow remaining on table resize.

The code below is just a sample I added to the DropShadow and I pretty sure this is a bug.

What happens when load up is fine. When you move items from the left listbox to the right listbox it seems fine.

EXCEPT, when one listbox becomes empty, the listbox shrinks, hence the table shrinks and then your left with this big black shadow on the right that goes up to the table. That is the shadow has not resized with the table.

If I addWidth="100%" to the Panel yes it works but then my screen design is not what I want I have this massive table on the screen. It's the solution I'm forced to use now.

<divclass="demoarea">

<divclass="demoheading">DropShadow Demonstration</div><asp:PanelID="Panel1"runat="server"CssClass="dropShadowPanel"Width="100%"><divstyle="padding:10px">

<tableborder="2"width="100%">

<tr>

<tdcolspan="3"align=center> </td>

</

tr>

<

tr><td>

<asp:ListBoxRows="20"SelectionMode="Multiple"ID="lbListLeft"runat="server"><asp:ListItem>Somewhere RSL Club, 555 Something St, Somewhere</asp:ListItem><asp:ListItem>20</asp:ListItem>

<asp:ListItem>D</asp:ListItem></asp:ListBox><br/></td><td><NOBR><inputvalue="Add >>" type="button"BR></NOBR><NOBR><inputvalue="Add <<" type="button"BR></NOBR><NOBR><inputvalue="Add All >>" type="button"BR></NOBR><NOBR><inputvalue="Add All <<" type="button"BR></NOBR></td><td>

<br/><asp:ListBoxRows="20"SelectionMode="Multiple"ID="lbListRight"runat="server"><asp:ListItem> RSL Club, 154 Somewhere Pde, Somewhere</asp:ListItem><asp:ListItem>2</asp:ListItem><asp:ListItem>3</asp:ListItem>

</asp:ListBox></td>

</

tr>

</

table>

Did you set "TrackPosition='true'" on the DropShadowProperties?


Yes I haveTrackPosition="true"as it came from the example.

Here's the complete code in a master page. YOu'll notice that once you move all items to one listbox the table shrinks I have mentioned. I've done some slight changing to the html but this content page should work standalone. Unless you tweak the Content Placer then you'll have to tweak the javascript.

<%

@.PageLanguage="C#"MasterPageFile="~/Site.master"AutoEventWireup="true"CodeFile="DropShadow.aspx.cs"Inherits="DropShadow_DropShadow"Title="DropShadow Sample" %>

<%

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

<

asp:ContentID="Content1"ContentPlaceHolderID="MiddleContent"Runat="Server"><atlas:ScriptManagerid="ScriptManager"EnablePartialRendering="true"runat="Server"/><divclass="demoarea"><asp:PanelID="Panel1"runat="server"CssClass="dropShadowPanel"><divstyle="padding:10px">

<

tableborder="0"width="100%">

<tr><td><tableborder=0width="100%">

<tr><tdalign="right"><asp:ListBoxRows="20"SelectionMode="Multiple"ID="lbListLeft"runat="server"><asp:ListItem>Kogarah RSL Club, 254 Railway Pde, Kogarah</asp:ListItem><asp:ListItem>20</asp:ListItem><asp:ListItem>30</asp:ListItem><asp:ListItem>40</asp:ListItem><asp:ListItem>A</asp:ListItem><asp:ListItem>B</asp:ListItem><asp:ListItem>C</asp:ListItem><asp:ListItem>D</asp:ListItem></asp:ListBox></td></tr></table><br/><br/></td><td><NOBR><inputvalue="Add >>"onclick="moveDualList( this.form.ctl00$MiddleContent$lbListLeft, this.form.ctl00$MiddleContent$lbListRight, false );"type="button"style="width:90"><BR></NOBR><NOBR><inputvalue="Add <<"onclick="moveDualList( this.form.ctl00$MiddleContent$lbListRight, this.form.ctl00$MiddleContent$lbListLeft, false );"type="button"style="width:90"><BR></NOBR><NOBR><inputvalue="Add All >>"onclick="moveDualList( this.form.ctl00$MiddleContent$lbListLeft, this.form.ctl00$MiddleContent$lbListRight, true );"type="button"style="width:90"><BR></NOBR><NOBR><inputvalue="Add All <<"onclick="moveDualList( this.form.ctl00$MiddleContent$lbListRight, this.form.ctl00$MiddleContent$lbListLeft, true );"type="button"style="width:90"><BR></NOBR></td><td>

<br/>

<br/><asp:ListBoxRows="20"SelectionMode="Multiple"ID="lbListRight"runat="server"><asp:ListItem> RSL Club, 154 Railway Pde, Kogarah</asp:ListItem><asp:ListItem>2</asp:ListItem><asp:ListItem>3</asp:ListItem><asp:ListItem>4</asp:ListItem><asp:ListItem>5</asp:ListItem><asp:ListItem>D</asp:ListItem><asp:ListItem>G</asp:ListItem><asp:ListItem>K</asp:ListItem><asp:ListItem>Z</asp:ListItem><asp:ListItem>55</asp:ListItem></asp:ListBox></td>

</

tr>

<

tr><tdcolspan=3align=center><asp:ButtonID="btnSave"Text="Save"runat=server/></td></tr>

<

tr><tdcolspan=3>

</

td></tr>

</

table>

<

br/><br/><hr/><p><asp:PanelID="CollapseHeader"runat="server"style="cursor: pointer;"width="100%"><asp:LabelID="Label1"runat="server"Text="Label">Show Details...</asp:Label></asp:Panel><asp:PanelID="Panel2"runat="server"style="overflow:hidden;height:0"width="100%">

Not many details here. This is just a demo to show how the DropShadow will react properly to changes in the size of the panel it is attached to.

</asp:Panel><atlasToolkit:CollapsiblePanelExtenderID="cpe1"runat="server"><atlasToolkit:CollapsiblePanelPropertiesTargetControlID="Panel2"Collapsed="true"CollapsedText="Show Details..."ExpandedText="Hide Details"TextLabelID="Label1"ExpandControlID="CollapseHeader"CollapseControlID="CollapseHeader"SuppressPostBack="true"/></atlasToolkit:CollapsiblePanelExtender></p></div></asp:Panel><divclass="demobottom"></div></div><atlasToolkit:DropShadowExtenderID="dse"runat="server"><atlasToolkit:DropShadowPropertiesTargetControlID="Panel1"Width="5"Rounded='true'Opacity=".75"TrackPosition="true"ID="dsBehavior"/></atlasToolkit:DropShadowExtender>

<

SCRIPTLANGUAGE="JavaScript">

<!-- Begin

// Compare two options within a list by VALUES

function

compareOptionValues(a, b)

{

// Radix 10: for numeric values, Radix 36: for alphanumeric valuesvar sA = parseInt( a.value, 36 );var sB = parseInt( b.value, 36 );return sA - sB;

}

// Compare two options within a list by TEXT

function

compareOptionText(a, b)

{

// Radix 10: for numeric values, Radix 36: for alphanumeric valuesvar sA = parseInt( a.text, 36 );var sB = parseInt( b.text, 36 );return sA - sB;

}

// Dual list move function

function

moveDualList( srcList, destList, moveAll )

{

// Do nothing if nothing is selectedif (( srcList.selectedIndex == -1 ) && ( moveAll ==false ))

{

return;

}

newDestList =

new Array( destList.options.length );var len = 0;for( len = 0; len < destList.options.length; len++ )

{

if ( destList.options[ len ] !=null )

{

newDestList[ len ] =

new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );

}

}

for(var i = 0; i < srcList.options.length; i++ )

{

if ( srcList.options[i] !=null && ( srcList.options[i].selected ==true || moveAll ) )

{

// Statements to perform if option is selected, Incorporate into new list

newDestList[ len ] =

new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );

len++;

}

}

// Sort out the new destination list

newDestList.sort( compareOptionValues );

// BY VALUES//newDestList.sort( compareOptionText ); // BY TEXT// Populate the destination with the items from the new arrayfor (var j = 0; j < newDestList.length; j++ )

{

if ( newDestList[ j ] !=null ) destList.options[ j ] = newDestList[ j ];

}

// Erase source list selected elementsfor(var i = srcList.options.length - 1; i >= 0; i-- )

{

if ( srcList.options[i] !=null && ( srcList.options[i].selected ==true || moveAll ) )

{

// Erase Source//srcList.options[i].value = ""; srcList.options[i].text = "";

srcList.options[i] =

null;

}

}

}

// End -->

</

script>

</asp:Content>

DropDownList, UpdatePanel, ControlEventTrigger and TimerControl affecting other UpdatePane

I've run across a problem so I've created some sample code below that replicates what I'm seeing.

I've got an UpdatePanel(up_Test) that has a control in it. I've got a TimerControl that fires every 2 seconds and my UpdatePanel has a Trigger to refresh on my TimerControl's Tick event.

I've got a DropDownList on the page(ddl_Test), with an AutoPostBack="true", I've got another UpdatePanel on the page that has a Trigger to refresh on my DropDownList's SelectedIndexChanged event. In this UpdatePanel I've got another DropDownList that gets its SelectedIndex set to the SelectedIndex of the first DropDownList.

Everything works as expected, except when I test it with IE6, when the TimerControl fires, the DropDownList in the second UpdatePanel gets refreshed. It doesn't seem to happen(or at least isn't noticable) with IE7(which is on the machine I'd been writing this on).

Basically, I wrote this big page that has a ton of different updatepanel's on it each with triggers to specific controls and that whole section worked great, but then on my masterpage, when I put a gridview with a timercontrol, suddenly, the page practically became unusable as all of the updatepanels suddenly trigger when the TimerControl fires. Is there some work-around I can do, or do I just need to drop the TimerControl and scrap the whole layout?

<

atlas:TimerControlID="tc_Test"runat="server"Interval="2000"Enabled="true"OnTick="tc_Test_Tick"/><atlas:UpdatePanelID="up_Test"runat="server"><ContentTemplate><asp:DropDownListID="ddl_Test"runat="server"></asp:DropDownList></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="tc_Test"EventName="Tick"/></Triggers></atlas:UpdatePanel><asp:DropDownListID="ddl_Test1"runat="server"AutoPostBack="true"OnSelectedIndexChanged="ddl_Test1_SelectedIndexChanged"/><atlas:UpdatePanelID="up_Test2"runat="server"><ContentTemplate><asp:DropDownListID="ddl_Test2"runat="server"></asp:DropDownList></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="ddl_Test1"EventName="SelectedIndexChanged"/></Triggers></atlas:UpdatePanel>

protected

void Page_Load(object sender,EventArgs e)

{

if (!Page.IsPostBack)

{

for (int i = 0; i < 10; i++)

{

string itemtext ="This is a long string to make it noticable " + i.ToString();

ddl_Test.Items.Add(itemtext);

ddl_Test1.Items.Add(itemtext);

ddl_Test2.Items.Add(itemtext);

}

}

}

protectedvoid ddl_Test1_SelectedIndexChanged(object sender,EventArgs e)

{

ddl_Test2.SelectedIndex = ddl_Test1.SelectedIndex;

}

protectedvoid tc_Test_Tick(object sender,EventArgs e)

{

Random r=newRandom();

ddl_Test.SelectedIndex = r.Next(9);

}

Mode="Conditional" on the update panels fixes the problem. I guess I just assumed putting in the <trigger> lines caused it to use the triggers but you have to change the updatepanel's mode too.

Wednesday, March 21, 2012

DropDownList flashing when inside an UpdatePanel

Hi,

Does anyone know why the second DropDownList in the following code 'flashes' when the selection is changed in the first one? - and how I can prevent this?

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

<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="true">

<asp:ListItem>One</asp:ListItem>

<asp:ListItem>Two</asp:ListItem>

<asp:ListItem>Three</asp:ListItem>

</asp:DropDownList>

<atlas:UpdatePanelID="UpdatePanel1"Mode="Conditional"runat="server">

<Triggers>

<atlas:ControlEventTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>

</Triggers>

<ContentTemplate>

<asp:DropDownListID="DropDownList2"runat="server"AutoPostBack="true">

<asp:ListItem>Flashing option one</asp:ListItem>

<asp:ListItem>Flashing option two</asp:ListItem>

<asp:ListItem>Flashing option three</asp:ListItem>

</asp:DropDownList>

</ContentTemplate>

</atlas:UpdatePanel>

I believe you need to put the first drop down list in an update panel too. Also set to conditional and without any triggers.

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

<atlas:UpdatePanelID="UpdatePanel1"Mode="Conditional"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="true">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>

<atlas:UpdatePanelID="UpdatePanel2"Mode="Conditional"runat="server">
<Triggers>
<atlas:ControlEventTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>
</Triggers>
<ContentTemplate>
<asp:DropDownListID="DropDownList2"runat="server"AutoPostBack="true">
<asp:ListItem>Flashing option one</asp:ListItem>
<asp:ListItem>Flashing option two</asp:ListItem>
<asp:ListItem>Flashing option three</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>


Many thanks for the reply, but unfortunately I still got the same problem with your fix - however - I have since downloaded Internet Explorer 7 beta 2 and the problem has gone away with that...

Thanks,

Keith


I'm having the same problem - I have a drop down that populates the Gridview depending on the selected value. I have tried the suggested soultion with a UpdatePanel control around my drop down list and another around my GridView.

Anyone have any other suggestions other than to try IE 7?

Thanks
I am having the same problem. The problemgoes away in IE 7. I think the problem is with only drop down list andlistbox control. All other other control like textboxes do not flash.As far i know drop down and listbox are not rendered in the same wayhas textboxes...i can think it has to do with IE6...i may be wrong...

Murali

For me, this flicker only occurs on pages that have a Flash movie embedded in the page. I am using the Cascading Drop Down from the Atlas Control Toolkit and everywhere that there is a flash movie, I get the flicker, if I remove the movie, the flicker goes away.

Any thoughts?


Hi, here it happen the same...dropdown and listitem refresh on IE6....

really dont know why it happens on microsoft browser and not happen on firefox....

anyone knows how to fiz it on IE6? i cant find a way.

Has anyone found a way to solve this with IE6?

As long as they are outside of the UpdatePanel it works fine.


From what I've seen and read no... At least not that I've found.


Does anybody know if this issue been resolved in CTP july release

Thanks

Murali Bala


Hi,

DropDownList And ListBox are windows controls, so there is no way to stop this flicker unless MS themselves release some patch for pre-IE7 browsers. If you notice...No HTML control can draw over a DropdownList.

DropDownList event handler serevr side not called

Hello,

this is driving me crazy, below code does a post back to the server but DropDownList1_SelectedIndexChanged1 is never called on the server !
All other buttons work just fine !
If I remove the drop down list from the trigger, than it is called. What is going on here ?

<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged1"
width="170px"></asp:dropdownlist>
<asp:updatepanel runat="server" id="upAvailability" updatemode="Conditional">
<ContentTemplate>
<asp:Label id="lbSearchResults" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btSearch"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="btNavigateHotels"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:updatepanel>

Hi

I recreated your page and linked up some events and it works fine. Here is what I ended up with, if you want to compare to yours.

HTML

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" Width="170px">
<asp:ListItem Value="1" Text="option 1"></asp:ListItem>
<asp:ListItem Value="2" Text="option 2"></asp:ListItem>
<asp:ListItem Value="3" Text="option 3"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel runat="server" ID="upAvailability" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lbSearchResults" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btSearch" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="btNavigateHotels" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" ID="btSearch" Text="search" OnClick="btSearch_Click" />
<asp:Button runat="server" ID="btNavigateHotels" Text="navigate hotels" OnClick="btNavigateHotels_Click" />
</form>

Codebehind

protected void Page_Load(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
lbSearchResults.Text = DropDownList1.SelectedItem.Text;
}
protected void btSearch_Click(object sender, EventArgs e)
{
lbSearchResults.Text = "Search";
}
protected void btNavigateHotels_Click(object sender, EventArgs e)
{
lbSearchResults.Text = "Navigate Hotels";
}

All the events fire correctly. When I attached to the aspnet_wp I could step through the events, and the label control reflected the text I wrote into it.

I even tried calling DataBind() on the DropDownList to see if that killed the event, but it still worked.

I bet thats even more frustrating? :)

Could you post more of your code/page so i can replicate exactly what you have?

Thanks

PaulTAG


Paul.

thanks for your great help on this. I worked around the problem by calling the event handler myself via checking the __EVENTTARGET of the form.

It is very weird because if I add another drop down list this one gets called ! Looking into the Forms collection on the server I cant find the method names there, also not for the buttons which do work (meaning I do not find any Button1_Click in any form value). How does this work, how does ASP know what method to call on the server ? I could than see why this is not happening in my case

Thanks

Joe

DropDownList causes a full page postback instead of only updating the UpdatePanel

I have a code for updating a DropDownList with items whenever another DropDownList triggers a SelectedIndexChanged event.

When I select an item in the DDLSelect dropdown, it causes a full page postback instead of just updating the UpdatePanel. This problem only occurs when I try to implement it in an existing project, and it works fine when if I try it in a new project.

I've updated my Web.config file to make my project compatible with AJAX, so I don't believe that's the problem.

I should add that I'm trying to use this inside an ascx UserControl file, so maybe there are known issues there.

Thanks in advance.

Please post the usercontrol code

OK, problem solved!

It was the Web.config after all. I had this line which caused the problem:

<

xhtmlConformancemode="Legacy"/>

I removed it and everything is fine.

Cheers.

DropDownExtender in a GridView issues (v1.0 beta)

I am trying to add a DropDownExtender within a GridView control using the code below but it fails i.e. The DropDownExtender is never displayed (no javascript errors). Then if I use the paging in the gridview to navigate to another page and hover over a row it causes a javascript error 'Line 196 Error: Object doesn't support this method or property'.

I've tried this with other controls (e.g. TextboxWatermark) in a GridView and they work ok but are a bit glitchy. Is this a known issue?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="Number,Sequence" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style='display:none;visibility:hidden;'>
<asp:LinkButton runat="server" ID="Option1" Text="Option 1" CssClass="ContextMenuItem" OnClick="OnSelect" />
<asp:LinkButton runat="server" ID="Option2" Text="Option 2" CssClass="ContextMenuItem" OnClick="OnSelect" />
<asp:LinkButton runat="server" ID="Option3" Text="Option 3 (Click Me!)" CssClass="ContextMenuItem" OnClick="OnSelect" />
</asp:Panel>
<asp:Label ID="TheLabel" runat="server" Text="Howydoing" />
<ajaxToolkit:DropDownExtender ID="DDE" runat="server" DropDownControlID="DropPanel" TargetControlID="TheLabel"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Number" HeaderText="Number" ReadOnly="True" SortExpression="Number" />
<asp:BoundField DataField="Sequence" HeaderText="Sequence" ReadOnly="True" SortExpression="Sequence" />
<asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="Reference" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>

Javascript where error occurs is: (this is part of the AjaxControlToolkit runtime scripts):

// NOTE: [rb] replaced with CommonToolkitScripts version
// var offsetParentLocation = Sys.UI.DomElement.getLocation(offsetParent);
// var parentBounds = Sys.UI.DomElement.getBounds(parent);
var offsetParentLocation = CommonToolkitScripts.getLocation(offsetParent);
var parentBounds = CommonToolkitScripts.getBounds(parent);

The problem here looks to be an issue with the current beta of ASP.NET AJAX, and I am following up with Shawn Burke and the ASP.NET AJAX team at Microsoft. The issue at hand is that ScriptManager currently emits all of its script for Extenders and ScriptReferences in it's own PreRender event which will happen before the PreRender event of the GridView. In the initial page request (Page.IsPostBack == false), a GridView bound using DataSourceID will delay binding until the last possible moment, which happens to be PreRender.

Until the ASP.NET AJAX team can address this issue, the quickest way to solve the bug is to temporarily add the following code to your Page or UserControl:

1protected void Page_Load(object sender, EventArgs e)2{3if (!Page.IsPostBack)4 {5 Grid.DataBind();6 }7}8 

Where Grid is the name of your DataGrid. This will cause the binding to the DataSourceID to happen in Load as opposed to PreRender.

Try the above and see if it solves your problem. I have another application I am working on that is exhibiting the same issue and this fixed it.


Thanks for that - that solved part of the problem to do with why it wasn't working on the first page display, however I was still getting the Javascript error. After a bit of debugging I found the following error in AjaxControlToolkit\Common\Common.js Line 196, which read:

var mediumThickness = this.parseBorderThickness("medium");

parseBorderThickness doesn't exist. however _borderThicknesses does and has values for thin, medium and thick. So changing the line to read:

var mediumThickness = this._borderThicknesses.medium;

solved the issue, however the DropDown is not quite aligned properly with the text so it looks like there is some additional work required in this area - maybe this will be fixed in the next release.


Thanks for pointing that out, that was a bad reference. The correct function name isparseBorderWidth not parseBorderThickness. I have made the change and checked it in and it should be corrected in the next toolkit release.

Can you provide me with some further details as to the alignment issue, or a sample I might be able to look at (source code/designwise) that I can try to use to figure out what might be causing a problem with the offset?


Source code is below. There are 2 issues:

1) The alignment of the DropDown box when hovering over 'TheLabel' is wrong in IE 6. This is correct when using Firefox 2.0. I am able to resolve this in IE by modifying the Common.js file like so:

if(defaultTdLeftBorderFound) offsetX -= mediumThickness + 4; //(Previously was -1)
if(defaultTdTopBorderFound) offsetY -= mediumThickness + 3; //(Previously was -1)

2) The glitchy behaviour I mentioned earlier seems to be a problem with other controls as well (at least TextBoxWatermark) which occurs when you navigate to the last page in a paged grid. I get a Javascript error in MicrosoftAjax.js: Line 451: Error: '_behaviors' is null or not an object

Default.aspx:
<%@. Page Language="C#" AutoEventWireup="true" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script runat="server">
protected void Page_Load(Object sender, EventArgs args)
{
if (!Page.IsPostBack)
{
GridView1.DataBind();
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style>
.ContextMenuPanel
{
background-color:white;
border: 1px solid #868686;
z-index: 1000;
cursor: default;
padding: 1px 1px 0px 1px;
font-size: 11px;
}
a.ContextMenuItem
{
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="Number,Sequence" DataSourceID="XmlDataSource2">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style='display:none;visibility:hidden;'>
<asp:LinkButton runat="server" ID="Option1" Text="Option 1" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option2" Text="Option 2" CssClass="ContextMenuItem" />
<asp:LinkButton runat="server" ID="Option3" Text="Option 3 (Click Me!)" CssClass="ContextMenuItem" />
</asp:Panel>
<asp:Label ID="TheLabel" runat="server" Text="Howydoing" />
<ajaxToolkit:DropDownExtender ID="DDE" runat="server" DropDownControlID="DropPanel" TargetControlID="TheLabel"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Number" HeaderText="Number" ReadOnly="True" SortExpression="Number" />
<asp:BoundField DataField="Sequence" HeaderText="Sequence" ReadOnly="True" SortExpression="Sequence" />
<asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="Reference" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource2" runat="server">
<Data>
<TheData>
<row Number="asdfasdf" Sequence="001" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="002" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="003" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="004" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="005" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="006" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="007" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="008" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="009" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="010" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="011" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="012" Title="eflwef fwe " Reference="fwefwewefwef"/>
<row Number="asdfasdf" Sequence="013" Title="eflwef fwe " Reference="fwefwewefwef"/>
</TheData>
</Data>
</asp:XmlDataSource>
</div>
</form>
</body>
</html>

Notes: Web.config is taken direct from C:\Program Files\MicrosoftASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\web_CTP.config and needsreferences to Microsoft.Web.Preview.dll and AjaxControlToolkit.dll


I've found that using a repeater table works just fine, but I continue to have problems with the GridView.

Suman Chakrabarti [MSFT]


I notive the alignment problem when placed inside a table with a border > 0px . If I set the boder to zero it lines up.
is this fixed in the current downloadable rc1 version?

Hi,

did you solve this problem? I have got the same problem at the moment. Is there a solution available?

--edit--

I just saw, my code is a little bit different

 <asp:HyperLink ID="hl1" runat="Server" NavigateUrl='<%# Eval("Id")%>' OnDataBinding="hl1_DataBinding"><asp:Label ID="TheLabel" runat="server" Text="Howydoing" /></asp:HyperLink>