Showing posts with label controls. Show all posts
Showing posts with label controls. Show all posts

Wednesday, March 28, 2012

Changing Background Color Of Text box ?

Hello,

I need something as Follow..

I am having one Data Entry form. Here I have many controls (All type of controls like Textbox, Dropdownlis, Checkboxex esc...)

Now when user focus any text box then its Background color should change. Can we do it using ATLAS, xmlScript, Javascript...

one more problem is that I am having nearly 20 Text boxes on my page so which way I can get this functionality using less efforts...

Atlas is a really "heavy" way to do this. I'd just do it with Javascript and CSS.

<style type="text/css">

.normal

{

background-color:inherit;

}

.focus

{

background-color:yellow;

}

</style>

<script type="text/Javascript">

function changeTextbox(control){

var x = document.getElementByID(control);

if (x.classname == "normal"){

x.classname = "focus";

}

else {

x.classname = "normal")

}

}

</script>


Nice..

But the Parameter CONTROL in function... comes from where ?

Means from where we can pass it ?


You pass the control paramater when you call the function from the onFocus even of your textbox. It would be just as easy to capture the sender though, and get the calling object of the function, so it didnt need a paramater.
You don't need atlas or ajax at all, some javascript and dhtml will do:
foreach (Control ctrlin Form.Controls){if (ctrl.GetType() ==typeof(TextBox)) { ((TextBox)ctrl).Attributes.Add("onfocus","javascript:this.style.backgroundColor='red'"); ((TextBox)ctrl).Attributes.Add("onblur","javascript:this.style.backgroundColor='white'"); }}

Changed control prefix doesnt apply when dragging control from toolbox

Hello,

due to problems with Intellisense not recognizing the new ajax controls such as updatepanel and scriptmanager I tried to give them a different prefix. I thought ajax would be nice instead of asp, so I specified this in my web.config

<add tagPrefix="ajax" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
However, when I drag 'n drop an Ajax control from the toolbox it will still get the asp prefix. Now I've done some custom control development, so I know you can give a control an attribute called ToolboxData where you can use a placeholder for the actual prefix. So did the Ajax developers not use this, or do I need to do something else to get my new prefix when I select a control from the toolbox?

hello.

well, I'm thinking that they've only used the tagprefixattribute to set the default attribute of the controls...


Yes, but the design surface and intellisense will normally use the prefix that is specified in the web.config. However, I think I may have found a bug. It seems there might be a problem is there's a newline character in the assembly attribute. Maybe you could try this out to confirm this?

Thanks!

change the visable of page controls

in my UserControl,there are 3 controls, DropDownList1,DropDownList2,TextBox1

DropDownList1,DropDownList2 are for the ajaxToolkit:CascadingDropDown

TextBox1.Visible=false;

but now when DropDownList1.SelectedItem.Text=="other",I want to change DropDownList2.Visible=false;TextBox1.Visible=true;

I make it via AJAX

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="TypeService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
</Scripts>
</asp:ScriptManager>

<script language="javascript">

...

Type_service.CheckOther(DropDownList1.value);

....

</script>

but the problem is now

how my TypeService.cs call the function in the CascadingDropDown.ascx.cs

Hi,shootarrow

I'm afraid that you cann't do this in that way.

You can do this at the client side!

Try this:

Default.aspx:

<%@. Page Language="C#" %>

<!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>

<script type="text/javascript">
// This function calls the Web Service method.
function EchoUserInput()
{
//Do something you want to do, e.g.delay the script execution
var echoElem = document.getElementById("EnteredValue");
WebService.HelloWorld(echoElem.value,SucceededCallback);
}
// This is the callback function that processes the Web Service return value.
function SucceededCallback(result)
{
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;
// Change the delay of the script execution back.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<h2>
Simple Web Service</h2>
<p>
Calling a simple service that echoes the user's input and returns the current server
time.</p>
<input id="EnteredValue" type="text" />
<input id="EchoButton" type="button" value="Echo" onclick="EchoUserInput()" />
</div>
</form>
<hr />
<div>
<span id="Results"></span>
</div>
</body>
</html>

WebService.asmx:

<%@. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String input)
{
System.Threading.Thread.Sleep(3000);
string inputString = Server.HtmlEncode(input);
if (!String.IsNullOrEmpty(inputString))
{
return String.Format("You entered {0}. The current time is {1}.", inputString, DateTime.Now);
}
else
{
return "The input string was null or empty.";
}
}
}

Hope this helps.

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115018.aspx

Change Event not fired when changed once or more then restored to its original value.

Hi.


I am trying to ATLAS-ize an existing application with lots of Master Detail controls.

As I don't want to write a heap of new code I am using UpdatePanels rather than writing web services even though my situation is similar to the one in the CascadingDropDown example (http://atlas.asp.net/atlastoolkit/CascadingDropDown/CascadingDropDown.aspx)


The problem I have though is that if I change the master listbox selected value (say from 0 to 1) then the Update Panel refreshes fine.

If I change it back from 1 to 0 the SelectedIndexChanged event does not fire leaving a load of incompatible info in the details listbox

I'm assuming that this is because when the page was first loaded the value was 0 so it does not recognize that a change has occurred.

I'd be grateful for advice on the optimum solution to this.

Ah Problem Semi Solved!


The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)

The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)


Ah Problem Semi Solved!


The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

I would appreciate some advice on things I can override to get this functionality back however as some of the ViewState is pretty huge but required without a lot of extra coding. Is their any way I can replicate what is happening automatically with __VIEWSTATE to my own custom hidden input (hdnViewStateId) (i.e. get it automatically submitted on a call back, get it passed back in the XML envelope and automatically update the value with the new one)

The other thing I was doing wrong was that I'd left in an old school Response.Write in my page which knackered up the XML sent! (By the way is there any way I could have switched on any error logging which would have alerted me to this last issue?)


Your drop down list is set to do a autopostback, correct? This would translate to a partial postback given that it's within the update panel.

Given that you've turned off the standard viewstate mechanism provided by ASP.Net, the "change" isn't going to be noticed 'cause the runtime can't compare what "was" (in the viewstate) with what "is" (in the form post). However, you can...

Take a look at this Fiddler trace of a site I quickly built using the update panel to do what you're doing with a drop down list (this is taken when the drop-down list auto posts back to the server):

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 305
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=DropDownList1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUKLTgwNzIyNjA5NA9kFgICAw9kFgICAw9kFgJmD2QWAgIDDxBkZBYBZmRkrJaJXj2KU%2FOTLiUUKLu7RDDJunM%3D&DropDownList1=2&__EVENTVALIDATION=%2FwEWBALyq5BnAp3kj%2BUKApKLpYsGApOLpYsGRIPIbgqWzDqL6Q8VoLqfhZnR%2BlM%3D&

You could grep out of the form post the object that created the postbck (__EVENTTARGET), and what its postback value is (DropDownList1=2). You could store the state of the last selected item value in whatever mechanism you choose and do your own compare, even in your custom page_load.

Thanks. I reckon that's probably the way to go.

I was contemplating (but probably wouldn't have actually done) a pretty horrible solution as I was playing with adding my own

__VIEWSTATE

hidden input with the GUID and it almost works if I strip out the extra "," that I get on the form post from the redundant ASP.NET added control of the same name!

I still hadn't sussed out how to change the XML envelope to reflect that change though..


When you say "change the XML envellop to reflect that change" you're talking about changing the XML response from the server that contains all the delta bits for the clientside framework, right (the XML that directs the client code to do its DHTML tricks to update the content within the UpdatePanel)?

So, before we go any further - your problem is that you can now detect when the change is made, but the atlas server code still doesn't and, therefore, doesn't include the right junk in the XML response back to the client to update the doodads in your UpdatePanel control?


Yes that's correct.

BTW: I've had a look at your blog and I suspect you're going to tell me that you know how to do this.

I'm a bit torn on the best way of doing this as.

I reckon__EVENTTARGET is probably the more robust way of doing it even though I lose a lot of the benefits of the ASP.NET module (I need to figure out how to store and retrieve the initial values of controls without using view state and raise the change events myself)

If I try and hijack the __VIEWSTATE control for my own purposes then a lot of the code is written for me already but my solution could break if a new version of ATLAS or update to ASP.NET comes out!


Actually Ben.

I've tried your suggestion and it's trickier than I thought it would be.

The problem is that when I select the original value in the Master ListBox nothing is sent back to the browser!

I assume that this is some sort of optimisation to only send back the things which are different and (as far as ASP.NET knows from looking at the old ViewState) it doesn't have to send anything back as they are the same.

It looks like I am going to need to integrate it with ViewState somehow. For the time being I've commented out my overrides and am sending all ViewState to the Client to get it working.

However I would be extremely grateful for suggestions of ways to get around this issue and get the benefits of both ServerSide ViewState Storage and ATLAS.


...let me dink around a bit with some stuff on my side here and try to duplicate what you're running into more accurately. This has got me curious about several things going on...


Can you visit this page and tell me how accurately this matches your situation:http://www.ben-rush.net/public/testsites/atlaswebsite3/.

I have a textbox and a listbox, the textbox updates its content to the selected index of the listbox when the selectedindex changes. The viewstate for the listbox is off. I don't believe that the listbox requires viewstate for identification of changes because the "change" will only occur when the index is changed; therefore a form post that includes the listbox as an eventtarget will be seen as a selectedindexchanged event. I could be wrong, but I seem to remember this being the case (I did some viewstate optimizations for a shopping cart system a long, long time ago).

Regardless, look at these two fiddler dumps, one during change from index 0 -> 1 (value 1->2), the other from 1->0 (value 2->1). Both show the value of the listbox.

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=2&TextBox1=0&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&

And the other...

POST /public/testsites/atlaswebsite3/Default.aspx HTTP/1.1
Accept: */*
Accept-Language: en-us
Referer:http://www.ben-rush.net/public/testsites/atlaswebsite3/
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
delta: true
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Host:www.ben-rush.net
Content-Length: 288
Proxy-Connection: Keep-Alive
Pragma: no-cache

ScriptManager1=myupdatepanel&__EVENTTARGET=ListBox1&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE=%2FwEPDwUJNTA5MjUzOTYxZGTFj5uiiDfrPSUZQz6IYXNKpb8xOQ%3D%3D&ListBox1=1&TextBox1=1&__EVENTVALIDATION=%2FwEWBwKJvNCXBgK9ueOMCQKy1sniBQKz1sniBQKw1sniBQKx1sniBQLs0bLrBlpXNeow%2BdPC39h7%2F1FxYfamkoLm&


I should probably mention that I have a trigger in the UpdatePanel as well.

I suspect that it may be a trigger optimisation causing the issue (for the same reason as previously described it can't realise that there is a change to process so returns an empty envelope)

<Triggers>

<atlas:ControlEventTriggerControlID="drpMasterListBox"EventName="SelectedIndexChanged"/></Triggers>

Well yes that is definitely working.

Do you have a trigger?

Is your UpdatePanel set to the same options as mine or is anything different?

(I haveMode="Conditional"RenderMode="inline")

In any event I'm thinking of doing it without update panels now and using a custom extender.

I was hoping that UpdatePanels would be a quick and dirty solution but I'm not progressing as fast as I wanted to and I suspect I may hit yet more obstacles because my UpdatePanel is in a UserControl which I was planning to embed in another UpdatePanel at Page Level.


No, I don't have a trigger. I changed my rendering modes to what you have, and it didn't change things (I wouldn't expect that it would). You can visit the same page URL I gave you earlier to confirm.

If you have a control in your update panel that does a postback automatically (say, the listbox control with its autopostback option on), then you have no need for a trigger. Triggers will only be useful for controls that don't postback automatically. I haven't researched triggers much, but if they're anything like binding objects then the control they're bound to needs to be AJAX savvy anyway.

Try turning off the trigger, I guess - and see what that does.


MartinSmithh:

The first thing I was doing "wrong" was that my page overrides Load and Save PageStateFromPersistenceMedium and stores it in a DB and just passes the GUID back and forth in a hidden field. This obviously means the ViewState updates never made it into my page.

well, though i haven't tried it, i think it's safe to assume that your field will allways be maintained if you add it to the page by using the registerhiddenfield of the clientscriptmanager api.

Monday, March 26, 2012

cc1 and cc2 prefix for controls

All --

Please help.

After upgrading from AjaxBeta2 to AjaxRC1, I now get some strange prefixes for the controls when I drag them from the Toolbox to an ASPX page, as follows...

<cc1:autocompleteextender id="AutoCompleteExtender1" runat="server" />
<cc1:dragoverlayextender id="DragOverlayExtender1" runat="server" />
<cc1:profileservice id="ProfileService1" runat="server"></cc1:profileservice>
<cc2:script id="Script1" runat="server" />
<cc1:timercontrol id="TimerControl1" runat="server"></cc1:timercontrol>
<asp:scriptmanager id="ScriptManager1" runat="server"></asp:scriptmanager>
<asp:scriptmanagerproxy id="ScriptManagerProxy1" runat="server"></asp:scriptmanagerproxy>
<asp:timer id="Timer1" runat="server"></asp:timer>
<asp:updatepanel id="UpdatePanel1" runat="server"></asp:updatepanel>
<asp:updateprogress id="UpdateProgress1" runat="server"></asp:updateprogress>

...so my question is...

Why do some controls use the expected "asp:" prefix and other use the odd "cc1:" or "cc2:" prefix?

How can this be fixed so that all controls use the same prefix, "asp:"?

Please advise.

Thank you.

-- Mark Kamoski

hello.
well, normally that is something that is defined by the programmer that builds the control through the use of the?taprefixattribute.?what's?happening?is?that?probably?the?controls?of?the?toolkit?didn't?define?that?prefix?and??now?you?get?a?default?prefix?when?you?drag?the?control?to?the?designer.

Wednesday, March 21, 2012

CascadingDropDown OnSelectedIndexChanged event not firing

Help!!!

I have 4 drop down list boxes that are extended by the CascadingDropDown control. All of the controls populate in sequence. I am using the OnSelectedIndexChanged event of the 4th DDL to trigger an UpdatePanel. I want to take the selection from the DDL (cmbPart) and add the item to the ListBox (lbParts). When I change the selection in cmbPart, no event fires. When I press the button on the panel (btnRemovefromList) the cmbPart_SelectedIndexChanged event DOES fire before the btnRemovefromList_Click event. I have also tried to use OnSelectedIndexChanged to fire a client side javascript function and that does not fire either. However, the onblur and onclick events DO fire.

According to previous posts on this topic, it was fixed. I have the 1.0.60914.0 version of the AtlasControlToolkit.dll installed along with version 2.0.50727.60725 of Microsoft.Web.Atlas.dll.

Ken J.

Here is the code:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"EnableEventValidation="false"%>

<%@dotnet.itags.org.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>Untitled Page</title>

</head>

<body>

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

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

<div>

Year<asp:dropdownlistid="cmbFrom"tabIndex="2"runat="server"Width="120px">

</asp:dropdownlist>

<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server">

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbFrom"

Category="Year"

LoadingText="{Loading Years...}"

PromptText="Select a Year"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetYears"

/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbMake"

ParentControlID="cmbFrom"

Category="Make"

LoadingText="{Loading Makes...}"

PromptText="Select a Make"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetMakes"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbModel"

ParentControlID="cmbMake"

Category="Model"

LoadingText="{Loading Models...}"

PromptText="Select a Model"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetModels"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbPart"

ParentControlID="cmbModel"

Category="Part"

LoadingText="{Loading Parts...}"

PromptText="Select Parts"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetParts"/>

</atlasToolkit:CascadingDropDown>

Make<asp:dropdownlistid="cmbMake"tabIndex="3"runat="server"Width="215px"></asp:dropdownlist>

Model<asp:dropdownlistid="cmbModel"tabIndex="4"runat="server"Width="250px"></asp:dropdownlist>

<INPUTid="txtPartType"type="hidden"runat="server"NAME="txtPartType">

<asp:labelid="lparterr"runat="server"Width="216px"ForeColor="Red"></asp:label>

<atlas:UpdatePanelID="upParts"runat="server"Mode="conditional">

<ContentTemplate>

Part<asp:DropDownListID="cmbPart"runat="server"Width="250px"OnSelectedIndexChanged="cmbPart_SelectedIndexChanged"></asp:DropDownList>

Selected Parts<asp:ListBoxid="lbSelected"tabIndex="10"runat="server"Width="215px"Height="85px"SelectionMode="Multiple"></asp:ListBox>

<asp:Buttonid="btnRemovefromList"style="WIDTH: 54px; font-size:xx-small"tabIndex="9"Text="Remove"

runat="server"onclick="btnRemovefromList_Click"/>

</ContentTemplate>

<Triggers>

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

<atlas:ControlEventTriggerControlID="btnRemoveFromList"EventName="Click"/>

</Triggers>

</atlas:UpdatePanel>

</div>

</form>

<scripttype="text/xml-script">

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

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

And the code behind:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid cmbPart_SelectedIndexChanged(object sender,EventArgs e)

{

lparterr.Text ="test";

}

protectedvoid btnRemovefromList_Click(object sender,EventArgs e)

{

lparterr.Text ="Test";

}

}

Maybe have a look atthis post?

Thanks David.

I found that the final DDL had to have AutoPostBack set to true. I also found that using the UpdatePanel to contain only the control I want updated by the ControlEventTrigger. If the DDL controls are contained in the UpdatePanel you will see the CascadingDropDown extender refresh each of the DDLs.

Ken J.

CascadingDropDown Not Cascading

I have wired 2 dropdownlists to the cascadingdropdown controls. My page code looks like this:

1<asp:DropDownList ID="StateDropDownList" runat="server" />2<ajax:CascadingDropDown ID="StateDropDownListCascadingDropDown" runat="server" Enabled="True" Category="StateName"3 PromptText="Select a state" ServiceMethod="GetDropDownStates" ServicePath="~/Site_Services/Datasets.asmx"4 TargetControlID="StateDropDownList" />56<asp:DropDownList ID="CountyDropDownList" runat="server" />7<ajax:CascadingDropDown ID="CountyDropDownListCascadingDropDown" runat="server" Enabled="True" Category="County"8 PromptText="Select a county" ServiceMethod="GetDropDownCounties" ServicePath="~/Site_Services/Datasets.asmx"9 ParentControlID="StateDropDownList" TargetControlID="CountyDropDownList" />

I've simplified the second web method to try anything to get the 2nd dropdownlist to work and no matter what, it still doesn't work. Here is the simplified method:

1 [System.Web.Services.WebMethod]2 [System.Web.Script.Services.ScriptMethod]3public CascadingDropDownNameValue[] GetDropDownCounties(string knownCategoryValues,string category)4 {5 List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>();6 values.Add(new CascadingDropDownNameValue("Test","Test"));7return values.ToArray();8 }

Here's what is posted:

The server returns no response. Any ideas?

j_gaylord:

5List values =new List();

Are you referring a generic List<> collection?

I got an article on Cascading dropdownlist athttp://www.aspalliance.com/1183 . Check it

Thanks


Yes. The code didn't print out properly as the Code screen in the forums ommited my < and >. I updated the code above. You'd think that it would work regardless because no matter what the values are, a value is being added to the collection. However, that's not the case.


any ideas?

nudge


Two things I would check are:

1. The webservice is decorated with [System.Web.Script.Services.ScriptService] attribute.
2. The correct web.config file and the AjaxControlToolkit.dll binary.

Thanks


Both of them are correct. I already have one drop down working. Its just the second one who's parent is the first is not.


j_gaylord:

Both of them are correct. I already have one drop down working. Its just the second one who's parent is the first is not.

In such case, the second dropdown should also fill, as the method [GetDropDownCounties] you wrote has nothing to do with the parent dropdownvalue. I have tested your code and its working fine for me. You messed up something for sure.

Thanks


Thanks for the positive insight. Any further suggestions?Wink

CascadingDropDown Method error 500

I have a couple of CascadingDropDown controls on an ASP.NET page and am filling them from a code behind function that makes a call to a SQL Server 2005 database. My problem is that sometimes I receive a 'Method error 500' when filling the second dropdownlist based on a parent control. I am concatenating three fields together and I can mix and match 2 of them, but when I use all three, I consistently get the error.

Example "Select StoreCode + ' ' + City + ' ' State as Name From Table".

Is there a data size limit with using this control?

Also, I am able to bind the same data to a dropdownlist not used in AJAX.

Thanks in Advanced,

Marc


I am encountering a similar problem with some CascadingDropDowns that help define someone's location. Whn I gt tothe City level, sometimes I get a 'Method Error 500' and sometimes I do not.

Your question "Is there a data size limit with using this control?" got me experimenting, and my results suggested that indeed there was a correlation between the error and the amount of data being returned.

So I installed IEInspector and fond that indeed, requests that return a lot of data are creating a problem. This is one of the responses I am getting:

{"Message":"Maximum length exceeded.","StackTrace":" at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
 
My next step is to use Reflctr to look at the code for System.Web.Script.Services.RestHandler.InvokeMethod and see what I discover.
 
Thanks for the data length suggestion!
 

Ken, thanks for the investigative work. Can you please keep me updated as to what you find?

I too will continue to debug this issue and will report any findings to this thread.

Thanks in advance,

Marc


Eureka!

Stepping thru the AJAX source code was tiring but informative.

In any event, here is my solution (if your underlying issue is different, YMMV).

I was hitting a size limit in the JSON conversion stuff, which fortunately can be customized without recompiling the code.

When returning custom objects (like the arrays returned by the CascadingDropDown web methods), the objects are serialized using object names, including their namespace. While my collections were only a few thousand items in length, the unfortunate choice of the long-winded namespace 'AjaxControlToolkit' and class name 'CascadingDropDownNameValue' results in ridiculous object bloat and blows out the default JSON string size by adding the long object name to every single object.

For example, a single City in my array of around 4000 of them is being returned like this:

"__type":"AjaxControlToolkit.CascadingDropDownNameValue","name":"Abanda","value":"2728903","isDefaultValue":false},{"

IMHO it would be much more efficient (and give us programmers less gray hairs!) if shorter names were used, like:

"__type":"AjaxCT.CDDNV","n":"Abanda","v":"2728903","def":false},{"

Or even better, instead of returning an array of objects, return a single object (thus avoiding the namespace.classname overhead in each array element) that contains a string with the data in it. That is exactly what I did in my earlier implementation using Michael Schwartz's AJAX.NET and my own custom code.

In any event, adding the following to my Web.Config solved my issues (so far):

<

system.web.extensions>
<scripting>
<webServices>
<jsonSerializationmaxJsonLength="5000000" />
</webServices>
</scripting>
</system.web.extensions>This link describes Web.Config settings for AJAX:

http://ajax.asp.net/docs/ConfiguringASPNETAJAX.aspx#microsoftweb

This forum thread was also helpful:

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

CascadingDropDown Issue?

I'm having this weird problem with the CascadingDropDown:
I'm using three DropDown controls in cascade, and a CommandButton to fill a gridview. When the last control fills up, and I press my CommandButton, I can't see the value of the last DropDown. I mean that the value arrives empty, but the other two have the right value.
One thing that I've noted is that this happend when the DropDown is populated with only one item.

Any help or guidance would be apreciated.Debugging a little more I've foud that the problem is the item marked as default in the DropDown. If I select the items manually, it works fine, but when I left untouched the dinamically populated DropDown's (with the items marked as default shown in them), then I recive an empty string as value.

Anyone has had this problem?

Regards

Thanks for the report. I've opened work item 2218 to track this. I believe I have a fix you can try.

In CascadingDropDownBehavior.js, change:

// if we didn't match the selected value, and we found a default
// item, select that one.
//
if (!matchedSelectedValue && defaultIndex != -1) {
e.options[defaultIndex].selected = true;
this.set_SelectedValue(e.options[defaultIndex].value);
}
if
(!inInit && !matchedSelectedValue && !gettingList) {
this.set_SelectedValue('');
}

To:

// if we didn't match the selected value, and we found a default
// item, select that one.
//
if (!matchedSelectedValue && defaultIndex != -1) {
e.options[defaultIndex].selected = true;
this.set_SelectedValue(e.options[defaultIndex].value);
} else if (!inInit && !matchedSelectedValue && !gettingList) {
this.set_SelectedValue('');
}

That fixes the problem for me in my simple scenario. Please let me know if it works for you, too.


I didn't realize it was so easy to change! Thank you a lot, now it works as expected.Big Smile

I've fixed this for the next release of the Toolkit as change 3778 in CodePlex:

CascadingDropDown's handling of default values for drop-downs that the user didn't interact with was such that an empty value would be seen on the server for the relevant .SelectedValue on postback. Fix that problem and add an automated test case to cover the scenario.

CascadingDropDown in User Controls

Hi all,

I ran into a problem the other day using CascadingDropDown and I thought I'd share it. It is this:

When using CascadingDropDown within a user control (or a custom control for that matter) you have two options for filling your dropdown list controls:

1. Use a web service method. This apparently (and I could be wrong here) makes it impossible for you to tune your results according to some information stored in the session. So it's fine for "static" data, but not fine for "dynamic" data which may depend on say, the current user.

2. Use a page method. That poses another problem; you don't know on what page your control will run, you can't decouple by using interfaces 'cause the methods the page has to implement need to be static (Shared in VB), so the best I could come up with is define a dummy interface which "reminds" the developer to implement those methods - and of course you need to implement them on every single page you use your user/custom control.

Now both these alternatives are not very appealing. Wouldn't it be better if CascadingDropDown could look in its container for the static methods instead of the Page?

Cheers

In this case,

u can just use normal dropdownlist control make it like cascadingDropDown, then put everything in the updatePanel


I am currently working on a composite control that creates multiple (1-xxx) controls inside of it dynamically (based on XML) one of them being a Cascading Drop Down control.

Once I get it working i'll post here to let you know how I did it.


Hi,

I just posted inanother thread about this issue. I agree it's a problem and think we should try to get it fixed in the Toolkit.

Thanks,
Ted