Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Wednesday, March 28, 2012

Change the default async timeout error message

I can't believe this question hasn't been asked before... How do I change the message that is displayed to the user when an async postback has timed out? I've searched the scriptmanager documentation and tried to handle the asyncpostbackerror or whatever event (which doesn't fire on a timeout), but I can't figure out how to do it. Any hints will be appreciated. Thanks.Hi,

You can add your own error handler as the following code:
function StartAsyncPostBack() {
WebService.set_timeout(2000);
WebService.RunForLongTime(0, Complete, OnError); // call a method with the signature of?RunForLongTime(int);
}
function OnError(result) {// your error handler
alert("error: " + result.get_message());
}

Hope this helps.

change mouse pointer on AJAX UPDATE

i can't understand why i do same page exacly the same (copy & past) and sometimes it worked OK sometime it said javascript error.

My goal is to Change mouse pointer while AJAX is updating something and after finishes to change it back. I have found some woderfull example

please take a look at it:

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

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

</head>

<body>

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

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<scriptlanguage="javascript"type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(InitializeRequest);

prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args)

{

$get('Container').style.cursor ='wait';

// Get a reference to the element that raised the postback,

// and disables it.

$get(args._postBackElement.id).disabled =true;

}

function EndRequest(sender, args)

{

$get('Container').style.cursor ='auto';

// Get a reference to the element that raised the postback

// which is completing, and enable it.

$get(sender._postBackSettings.sourceElement.id).disabled =false;

}

</script>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:LabelID="Label1"runat="server"Text="Update Me"></asp:Label>

<br/>

<br/>

<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

whats wrong here?

hello.

well, i think that the code you've written will only change the cursor when it's over the container html control. btw, i'm not finding that control on the page you've posted...


well it worked few times. Here is a link to the original sample:

http://encosia.com/2007/01/01/improved-progress-indication-with-aspnet-ajax/

look at it and maybe it will be more clearer what i am up to


hello.

well, but in the case of that sample, the complete form is wrapped by a div element which is named container (and that's why the cursor changes with the previous code)...


ok so what would be my solution not nesceserily this particular one but i have an AJAX based website with master page and multiple content pages and i need

notify user when ajax completes any given task Best and many years know way is to change mouse cursor How can i do that besides this example? or maybe it needs some corrections?


hello.

i haven't run the example, but i think it's working. what i'm trying to tell you is that you're missing a div. if you look at the sample, you should see that the first child of the body is a div element named container. when you start a partial postback, it'll change the cursor for that element. since it is the top element, that means that while the mouse cursor is over the space ocuppied by the div, you'll see that cursor during a partial postback. since you don't have this div in the code you've shown, i'm assuming that it simply doesn't work.

you must keep in mind is that you'll only see that cursor when the mouse is OVER that element!


Thank you very much


one more thing i would like to ask you Now i put my master page in div with specified tag So if press any button it changes mouse cursor but if i hover onto a other button or textbox it changes cursor to default state only if am hovering onto label or sometext data i can see hourglass How can do that if something is going on no matter where you put your mouse on the DIV container the cursor still would be a hourglass?

Monday, March 26, 2012

Challenging PageRequestManagerParserException error

Hello,

I received the following error today (using ASP.NET AJAX), and I'm unable to suss it out. Any ideas on what might be causing the below?:

Sys.WebForms.PageRequestManagerParserException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to response.write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'Master 544|updatePan'.

I believe I am using the latest version of System.Web.Extensions, Version=1.0.61025.0

Thanks in advance,
-Alex

Hi, I figured it out. There was a Response.Write() call in the aspx page (inline in the HTML). Apparently, this is not allowed when using UpdatePanels. Any more info available on this subject?

-Alex


Thanks for the info ... I didn't figure it was my update panel who cause my trouble ...

I use another way to do it. Thanks !

Catch a Sys.WebForms.PageRequestManagerServerErrorException that occurs when server is dow

Hello,

I have an ajax timer control that updates an update panel every couple of seconds. When/if the server is down, there is an error message in a popup that says

"Sys.WebForms.PageRequestManagerServerErrorException: An unknown error ocurred while processing the request
on the server. The status code reutrned from the server was: 12029"

Basically I want to be able to catch this exception so that the popup does not continue to occur.

Is this possible?

Thanks in advance.

Take a look at the following posts on my blog:

http://fredrik.nsquared2.com/viewpost.aspx?PostID=395&showfeedback=true

http://fredrik.nsquared2.com/viewpost.aspx?PostID=394&showfeedback=true

You can also use the PageRequestManager, for example (This code should be located on the client):

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
if (args.get_error() != undefined)
{
var errorMessage;
if (args.get_response().get_statusCode() == '200')
{
errorMessage = args.get_error().message;
}
else
{
errorMessage = 'An unspecified error occurred. ';
}
args.set_errorHandled(true);
alert(errorMessage);
}
}


That's just what I needed. Thank you.

Cascasding drop down - Error 500

Hi
I am playing with the cascading drop down control...
i have written a method to get data from sql 05 database and return andarray of CascadingDropDownNameValue. (i watched one of the how towebcasts on it)....anyway, i can get it to work else where but forsome reason its not working with this one.
I know the method is returning the right data as i have another methodwhich returns all values in a string[] i then dump on the screen andall is ok.
My CCD declaration.

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

<atlasT:CascadingDropDownProperties

Category="CategoryName"

ParentControlID="ddlClass"

TargetControlID="ddlCourses"

PromptText="All"ServiceMethod="GetCoursesByIdClass"

ServicePath="webservices/FillDropDowns.asmx"/>

</atlasT:CascadingDropDown>

My method...

[WebMethod]

publicCascadingDropDownNameValue[] GetCoursesByIdClass(string knownCategoryValues,string category)

{

// Get connection string from web.config

string dsn = System.Configuration.ConfigurationManager.ConnectionStrings["connCleo"].ConnectionString;

string[] categoryValues = knownCategoryValues.Split(':',';');

int idClass =Convert.ToInt32(categoryValues[1]);

// SQL script

string sql =@dotnet.itags.org."SELECT c.idCourse, c.chrName FROM cleo.Course c

JOIN cleo.CourseAssign ca ONca.idCourse=c.idCourse

WHERE idClass=@dotnet.itags.org.idClass

ORDER BY c.chrName";

// Generic list for collection

List<CascadingDropDownNameValue> cascadeCollection =newList<CascadingDropDownNameValue>();

// Open connection and execute command...loop through reader and add items to list.

using(SqlConnection conn =newSqlConnection(dsn))

using (SqlCommand cmd =newSqlCommand(sql, conn))

{

cmd.Parameters.AddWithValue("@dotnet.itags.org.idClass", idClass);

conn.Open();

using (SqlDataReader reader = cmd.ExecuteReader())

{

while (reader.Read())

{

cascadeCollection.Add(newCascadingDropDownNameValue(reader.GetString(1), reader[0].ToString()));

}

}

}

// return collection as an array.

return cascadeCollection.ToArray();

}


I dont know of anyway i can debugthis to see if i am infact getting the correct values back(not surewhat values i need to pass to the method to mimic the call from thetoolkit.)?

Hopefully someone can see where i am going wrong.??

Thanks
Steve

OK, so i am pulling my hair out and have no idea where to look for help other than here.

I have put the same code in another project and it works fine.

The only difference that i can see is the version of the Atlas and Toolkit dll.

The date stamp on the one that works is 04/05/2006
The one that doesnt work is 27/06/2006

So begs the question....what has changed in the June CTP that stops my service from working?

Any ideas?
Steve


Again...the brick wall.
I added in the new CTP dll's to my project that works and it still works.

If i add the old dll's into my not working project...i dont get error 500, but i do get a popup error when trying to change the selection of parent ddl...(eventvalidation error) and no, nothing is bound to the Drop down.

:-(

Steve


sorted it!!!!

I was missing stuff from the web.config file !!!

Well thats two hours of my life gone!!!

Steve


OK...new error now. i seem to be speaking to myself here but if anyone does join in maybe they can help.

The drop down is not binding fine...problem is when i try and postback (with button) i get a postback validation error (there are a few posts on here with no clear answer, none regarding the CDD control though)...anyway, so i turn of validation and the value in the second drop down list has nothing...it should be an number (as id for the text on display...nothing odd there).

I have tried

protectedoverridevoid Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(this.UniqueID);
base.Render(writer);
}

but this has no affect.

Steve


i was a touch hasty with my previous post...there is a value in the selectedvalue property....however i was checked that selectedindex > 0...even though it was, it wasnt (if that makes sense - the debugger says 0)...however i got round this withstring.IsNullOrEmpty(ddl.SelectedValue)

But now i have to have eventvalidation off.

What are the implications of this...surely this isnt correct? I must be able to have it turned on...not sure what i does but feel like i'm missing out!!!!!!

Anybody?

Steve


Seee http://forums.asp.net/thread/1293293.aspx #20

Event Validation just makes sure the values you posted from your dropdown are valid values you populated it with. But seeing as the cascading dropdown populates from script, this wont/cant work and if you need to, validate the values on the server (its a security thing)

CascadingDropDowns from bad to worse...

I was getting a [Method Error 500] on a DropDown and was combing through the posts trying to find a solution. I stripped my code down to two simple DropDowns with CascadingDropDown controls attached to them. I was able to get the top level control to populate correctly but was still getting the Eror 500 on my child DropDown. One of the posts I saw suggested making my Web Service methods Shared (I'm using VB). I tried that and now my original DropDown stopped populating at. The Web Service code isn't being reached at all. I tried removing the Shared designation from my methods but the problem has not gone away. I have cleared my IE cache and completely recreated the project. Still, I can't get a single DropDown to populate usnig a Cascading DropDown and a WebService.Here's my aspx markup:

Here's the code in my WebService: _ _ _ _Public Class Locations Inherits System.Web.Services.WebService Private Shared ConnString As String = ConfigurationManager.ConnectionStrings("Inventory").ToString() Private Shared SqlCN As New SqlConnection(ConnString) _ _ Public Shared Function GetLocations() As CascadingDropDownNameValue() Try Dim Ds As DataSet = GetLocationDs() Ds.Tables(0).DefaultView.Sort = "Text ASC" Dim Values As New List(Of CascadingDropDownNameValue) For Each Dr As DataRow In Ds.Tables(0).DefaultView.Table.Rows Values.Add(New CascadingDropDownNameValue(Dr("Text").ToString(), Dr("Value").ToString())) Next Return Values.ToArray() Catch ex As Exception Dim newEx As Exception = ex Return Nothing End Try End Function Private Shared Function GetLocationDs() As DataSet Try Dim SqlCmd As SqlCommand = SqlCN.CreateCommand() Dim PTextColumn As New SqlParameter() Dim PValueColumn As New SqlParameter() Dim PTableName As New SqlParameter() Dim SqlDA As SqlDataAdapter = New SqlDataAdapter() Dim DropDownDS As DataSet = New DataSet() Dim I As Integer = 0 With PTextColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TextColumn" .Value = "Location" End With With PValueColumn .DbType = DbType.String .ParameterName = "@dotnet.itags.org.ValueColumn" .Value = "Location" End With With PTableName .DbType = DbType.String .ParameterName = "@dotnet.itags.org.TableName" .Value = "HE_Locations" End With With SqlCmd .CommandType = CommandType.StoredProcedure .CommandText = "usp_GetDropDownValues" .Parameters.Add(PTextColumn) .Parameters.Add(PValueColumn) .Parameters.Add(PTableName) End With SqlDA.SelectCommand = SqlCmd If SqlCN.State <> ConnectionState.Closed Then SqlCN.Close() End If SqlCN.Open() SqlDA.Fill(DropDownDS, "Values") Return DropDownDS Catch ex As Exception Throw New DataException("GetDropDownValues failed.", ex) Return Nothing Finally SqlCN.Close() End Try End FunctionEnd ClassIf anyone has any ideas, I would sure like to hear them. I'm about ready to pull out my AJAX manual and roll my own. I have lost a whole day on this. Even if I get my original DropDown working I still have the ubiquitous Method Error 500 to deal with.Btw, the code in my Catch block was simply a place to put a breakpoint for debugging so I could read exception mesage if there was one. There wasn't.Thanks!

Well, that didn't come out very well, did it?

Actually, nevermind. For some reason, after using the I.E. Devloper Toolbar, scripting in I.E. was disabled. I also figured out my Method Error 500 problem. I realize now that the parameters in the method signature have to match the example exactly - even the case. I assumed that wouldn't matter since I'm using VB.

Thanks.

Saturday, March 24, 2012

CascadingDropDownList Internal Error 500

Hi,

I am trying to use a CascadingDropDown list, the ParentDropDownList show up correctly, however, the Childdropdownlist give an error:

ChildDropDownList contains:
Prompt text
[Method error 500]

Here is the code I used:

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<br/>

<asp:DropDownListID="DropDownListLevel6xx"

runat="server"

DataSourceID="ods_Level6"

DataTextField="LEVEL6"

DataValueField="LEVEL6"Width="126px"

>

</asp:DropDownList>

<asp:DropDownListID="DropDownListLevel7xx"

runat="server"Width="153px"

>

</asp:DropDownList>

<br/>

<br/>

<br/>

<asp:ObjectDataSource

ID="ods_Level6"

OldValuesParameterFormatString="original_{0}"

SelectMethod="GetAllLevel6"

runat="server"

TypeName="DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level72TableAdapter"

></asp:ObjectDataSource>

<ajaxToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"

Category="LEVEL7"LoadingText="Please wait..."ParentControlID="DropDownListLevel6xx"PromptText="Select a level 6 filter"

TargetControlID="DropDownListLevel7xx"ServicePath="Level67Service.asmx"

ServiceMethod="GetLevel7ByLevel6Id"/>

And the web service:

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

publicclassLevel67Service : System.Web.Services.WebService {

[WebMethod]publicCascadingDropDownNameValue[] GetLevel7ByLevel6Id(string knownCategoryValues,string category) {

string[] _categoryValues = knownCategoryValues.Split(':',';');

String _level6 =Convert.ToString(_categoryValues[1]);

List<CascadingDropDownNameValue> _level7list =newList<CascadingDropDownNameValue>();

DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level71TableAdapter _level7Adapter =new DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level71TableAdapter();

foreach (DataRow _rowin _level7Adapter.GetLevel7byLevel6(_level6)) {

_level7list.Add(newCascadingDropDownNameValue(_row["LEVEL7"].ToString(), _row["LEVEL7"].ToString()));

}

return _level7list.ToArray();

}

}

I have tested the web service, it produce the right result.

Thanks in advance for any help!

Not sure if this will help, this is the web.config file..

Any help will be very much appreciated...

<?xml version="1.0"?>

<configuration>


<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

<connectionStrings>

<REMOVED for sercurity reason>
</connectionStrings>

<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<globalization culture="en-GB"
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"/>


<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>


</configuration>


Hi,

Error with status code 500 indicates that there is a problem when theserver tries to process the request. There can be variant causes. Any exceptioncould be a candidate. So the problem is mainly about how to find out the realcause of the error. Here are several options:

1. Set a break point in the code that is responsible for process therequest, then debug through it to find out the exception being thrown;

2. The real error message is usually returned in the response. We can useHttp Sniffer (e.g., Fiddler) to peek into the traffic between the client andserver to find out the error message.

Then it won't betoo difficult to solve it after the cause is known.

CascadingDropdownList [Method Error 500]

Still trying to get these dropdowns to work. I have created a page with a single ddl that should be populated from the web service and has no parents but I still get the [method error 500] as the values, what am I mising here?

ddl.aspx

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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">
<asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>

<asp:DropDownList ID="Region" runat="server" >
</asp:DropDownList>

<cc1:CascadingDropDown
Category="Region"
Enabled="true"
PromptText="Please work..."
ID="CascadingDropDown2"
TargetControlID="Region"
ServiceMethod="GetCountries"
ServicePath="CountriesByRegion.asmx"
runat="server">
</cc1:CascadingDropDown>

</form>
</body>
</html>

CountriesByRegion.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports PFCEnergy.Refining.Country.Business
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class

Hi,

I too get the same error . Have you sorted the problem ?

Pls help if its working for u .

Thanks.


Yeah got it working, I added the bold and removed the struck through. Good luck.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
PublicShared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class


Hi,

Iam not using list as u did in web method, So i thinkImports System.Collections.Generic is not needed.

Then i am not using Static (C#) in function.

So what would be wrong in my case?

Thanks.



Hi everyone, I had the same problem and after a little tweaking it works!

Here is the tip:

Please make that the database datatype matches the .NET datatype.If you have a different datatype in your database, you should TYPE CAST it to the corresponding .NET type.
string make = (string)dr["Make"];
int makeId = (int)dr["MakeID"];

.NET Framework Type

ADO.NET Database Type

SQL Data Type

String

Varchar

Varchar()

String

Nvarchar

Nvarchar()

String

NChar

Nchar()

String

NText

NText

String

Text

Text

Double

BigInt

Float

DateTime

DateTime

Datetime

DateTime

SmallDateTime

Smalldatetime

Int

Int

Int

Int64

BigInt

Bigint

Int16

SmallInt

smallint

Byte[]

Binary

Binary()

Byte[]

Image

Image

Byte[]

VarBinary

Varbinary()

Byte

TinyInt

Tinyint

Bool

Bit

Bit

Decimal

Decimal

Decimal

Decimal

Money

Money

Decimal

SmallMoney

SmallMoney

Float

Float

Float

Guid

UniqueIdentifier

Uniqueidentifier

Real

Real

Real

CascadingDropDownList - cant handle more than 765 items!

Hello,

My CascadingDropDownList gives me Method 500 error when more than 765 items are returned from the webservice! Is there a way to fix this? Thanks..

Hi,

that's probably related with the limit for the max size of the JSON payload set by ASP.NET AJAX. You can change it in the web.config:

<jsonSerialization maxJsonLength="500" />


this certainly worked! thank you!
Thanks! Helped me alot.
I have tried putting that in every section and it always errors out as unkown element, if someone can help I would really appreciate it!

Hi,

it must be added inside the configuration -> system.web.extensions -> scripting -> webServices section.


Thank you!

Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!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>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Hi,

I have changed the web config maxJsonLength to 1000. But i dont have that many values. First dropdown is giving me a value but on the second dropdown I am getting method error 500. My webservice code is as follows.

Imports

System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

<WebService(Namespace:=

"http://tempuri.org/")> _
<System.Web.Script.Services.ScriptService()> _

Public

Class MIService
Inherits System.Web.Services.WebService
Shared _DocumentAs XmlDocument
Shared _lockAsNewObject
PublicReadOnlyProperty Document()As XmlDocument
Get
If (_DocumentIsNothing)Then
SyncLock _lock
_Document =New XmlDocument
_Document.Load(HttpContext.Current.Server.MapPath("~/App_Data/MIService.xml"))
EndSyncLock
EndIf
Document = _Document
ExitProperty
EndGet
EndProperty
PublicReadOnlyProperty Hierarchy()AsString()
Get
Dim _HeirarchyAsString() = {"city","zip"}
Return _Heirarchy
EndGet
EndProperty
<WebMethod()> _
PublicFunction GetDropDownContents(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
'Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionaryAsNew StringDictionary
knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
EndFunction
EndClass

My code for aspx file is:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="False"%>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!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>
<scriptrunat="server">
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()
ReturnNew MIService().GetDropDownContents(knownCategoryValues, category)EndFunction
</script>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList><br/>
<asp:DropDownListID="DropDownList3"runat="server"AutoPostBack="True"Width="200px">
</asp:DropDownList><br/>
<br/>
<asp:LabelID="Label1"runat="server"Width="224px"></asp:Label><br/>
<br/>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServiceMethod="GetDropDownContentPageMethod"TargetControlID="DropDownList2"></cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown3"runat="server"Category="county"LoadingText="[loading County..]"ParentControlID="DropDownList2"PromptText="Please select county."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList3"></cc1:CascadingDropDown>
<br/>
<br/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Thank You,

Nepalaya


Hi,

what's the content of the 500? You can useFiddler to examine it.


I hope u get it the way you want, but 765 items in a drop down list isn't very user friendly? Think about screen res?

Maybe test out autocomplete control?

Just giving my view, but if you want 1000 items in a drop down list, go for it :P (I know how annoying it is when people try to divert you from the solution you want, so go for what is best in your app, just throwing out a suggestion)


Hi,

The problem resolved. It was not related with the lenght. Page method was not working so change the service method name to GetDropDownContents and it works.

<

cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="city"LoadingText="[loading City...]"PromptText="Please select a city."ServiceMethod="GetDropDownContents"ServicePath="MIService.asmx"TargetControlID="DropDownList1">
</cc1:CascadingDropDown><cc1:CascadingDropDownID="CascadingDropDown2"runat="server"Category="zip"LoadingText="[Loading Zip...]"ParentControlID="DropDownList1"PromptText="Please enter zip."ServicePath="MIService.asmx"ServiceMethod="GetDropDownContents"TargetControlID="DropDownList2">
</cc1:CascadingDropDown>

Thanks,

Nepalaya


Hello freinds,

I am not able to fill the cascading drop down using database. Does any one have fill it with the database??

Please help me i am stuck with this problem.

Thaks in advance.


Hi,

I get method error 500 in dropdownlist1 . Iam using WEB SERVICE .

i used <jsonSerializationmaxJsonLength="500" /> in web.config but still i get the error.

Can any one help ?

Thanks

CascadingDropDownList - Am i being a complete tool?

Hey,

Trying to get my head round these CascadingDropDownLists but i am continually returned with a [Method Error 500] error.

This is my code for 'Default.aspx'


<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %
<!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>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
Category="Author"
TargetControlID="DropDownList1"
ServiceMethod="FillMe"
ServicePath="WebService.asmx"
PromptText="Please select a category"
>
</ajaxToolkit:CascadingDropDown>
</form>
</body>
</html>

And my webservice, WebService.asmx, is as follows:

using System;using System.Configuration;using System.Web;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Web.Services;using System.Web.Services.Protocols;using AjaxControlToolkit;using System.Data;using System.Data.SqlClient;/// <summary>/// Summary description for WebService/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class WebService : System.Web.Services.WebService { [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public static CascadingDropDownNameValue[] FillMe(string knownCategoryValues, string category) { string connString = ConfigurationManager.ConnectionStrings["tenderlistDB"].ConnectionString; SqlConnection conn = new SqlConnection(connString); DataTable dt = new DataTable(); string Sql = "SELECT [ID], [Name] FROM tblCategories WHERE ParentID=@dotnet.itags.org.ParentID ORDER BY [Name] ASC"; try { conn.Open(); SqlCommand comm = new SqlCommand(Sql, conn); comm.Parameters.AddWithValue("@dotnet.itags.org.ParentID", "0"); SqlDataAdapter adapt = new SqlDataAdapter(comm); adapt.Fill(dt); } finally { conn.Close(); } List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); for (int i = 0; i < dt.Rows.Count; i++) { CascadingDropDownNameValue CCD = new CascadingDropDownNameValue(); CCD.name = dt.Rows[i]["Name"].ToString(); CCD.value = dt.Rows[i]["ID"].ToString(); values.Add(CCD); }return values.ToArray(); }}

Anyone have an idea as to why it's just not working?

Cheers,

Sean


Most likely you have an exception being thrown in your WebMethod. Set a breakpoint in it and use the site in Debug mode. Step through the WebMethod and see if you are getting an exception. This is usually the case for me. The other thing I have seen is too much information being returned, but I think that is another error number. The Execption will not be returned by the Web Service, so AJAX throws a 500 error up at you.


Thanks for getting back to me.

I've never really used the debug function, but i stuck some breakpoints in the code and hit F5, and it all ran ok.

If i run it in debug mode, instead of Error method 500, i get an Error Method 12031...Could that be anything?

In terms of the SQL, it returns 12 rows when run through Sql Query Analyzer.

Appreciate your help!


Been thinking about this a little over lunch. Have you marked your Web Service and Web methods with AJAX attributes?

The Class should have this attribute:

<System.Web.Script.Services.ScriptService()> _

The Web Method this one:

<System.Web.Script.Services.ScriptMethod()> _

So a method would resemble the following:

<WebMethod()> _

<System.Web.Script.Services.ScriptMethod()> _

PublicFunction GetMarkets(ByVal knownCategoryValuesAsString, _

ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()

Dim kvAs StringDictionary = _

AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

Dim RegionIdAsInteger

IfNot kv.ContainsKey("Region")OrElseNot Int32.TryParse(kv("Region"), RegionId)Then

ReturnNothing

EndIf

Dim lcAsNew LocMarketController

Dim itemListAs LocMarketList = lc.GetLocMarketByRegion(RegionId)

Dim valueAsNew List(Of AjaxControlToolkit.CascadingDropDownNameValue)

ForEach itemAs LocMarketInfoIn itemList

value.Add(New AjaxControlToolkit.CascadingDropDownNameValue(item.Market, item.MarketId))

Next

Return value.ToArray

EndFunction


Hey,

Tried that but still no joy. Starting to get frustrating now hehe, anyone else got any ideas?

Cheers for the help!


Hey,


Just to let you all know i got it working...i rewrote it this morning when i got into work and its all working fine...not sure why though, i have a feeling I wasn't passing through the correct parameters, so when the


'StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);'

line was hit, the method would break!

Thanks for all the help.

CascadingDropDown with a DB causing stack overflow

I've struggled for days through examples and self discovery to get to where I am, and now I get a stack overflow error from my cascadingdropdown object which is attempting to retrieve data from a tableadapter. When the page loads I get a msgbox pop-up error which says: "Stack overflow at line: 116". I've tried commenting out most every line in the webservice function and that seems to have no discernible effect. Perhaps it's something in the aspx page? Any help greatly appreciated.

Here's my aspx:

-------------------------------------------

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %
<%@dotnet.itags.org. Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="ajaxToolKit" %
<!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>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />
<br />
<div>
<asp:DropDownList ID="ddl_GetService" runat="server">
</asp:DropDownList> <br />

<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList><br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList><br />
<br />
<br />

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server" TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices" ParentControlID="ddl_GetService" >
</ajaxToolKit:cascadingdropdown>
<br />
</div>
<br />
<br />
<br />

</form>
</body>
</html>


-------------------------------------------

Here's my asmx file:

-------------------------------------------

<%@dotnet.itags.org. WebService Language="VB" Class="wsGetServices" %
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports AjaxControlToolkit
Imports Facilities_WizardTableAdapters
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class wsGetServices
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetAllServices(ByVal sServRsn As String, ByVal sCode As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim ServiceTableAdapter As TBL_WZ_SERVICETableAdapter = Nothing
ServiceTableAdapter = New TBL_WZ_SERVICETableAdapter()
Dim Services As Facilities_Wizard.TBL_WZ_SERVICEDataTable = ServiceTableAdapter.GetServices()
Dim values As List(Of CascadingDropDownNameValue) = New List(Of CascadingDropDownNameValue)
Dim dr As Facilities_Wizard.TBL_WZ_SERVICERow

For Each dr In Services
sServRsn = dr.SERV_RSN.ToString()
sCode = dr.CODE.ToString()
values.Add(New CascadingDropDownNameValue(sServRsn, sCode))
Next dr

Return values.ToArray()

End Function

End Class

I discovered that it's a stack overflow because it's working! And the number of rows returned is rather large. So does anyone know how I can accomodate for that? I mean a drop down with say around 300 entries?

Thanks!


It's not clear to me why returning lots of entries should cause a stack overflow. Maybe run this page under the VS debugger and have a look at what's on the stack at the time - that should help narrow the problem down.

I am having a similar issue today. I know my webservice is working and it only returns 27 records. here is my ASMX file if anyone has any advice:

<%

@.WebServiceLanguage="VB"Class="LHMCSearchDD" %>

Imports

System.Web

Imports

System.Web.Services

Imports

System.Web.Services.Protocols

Imports

System.Collections.Generic

Imports

System.Data

Imports

System.Data.SqlClient

Imports

System.Configuration

Imports

AjaxControlToolkit

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

Public

Class LHMCSearchDDInherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetProducts(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()Dim cadapterAsNew dsSearchTableAdapters._PRODUCTTableAdapter' Dim cadapter As New dsSearch.DSTablesTableAdapters.countryTableAdapterDim ctableAsNew dsSearch._PRODUCTDataTable' Dim ctable As New ltcodebehind.DSTables.countryDataTable

cadapter.FillBrands(ctable)

Dim valuesAsNew List(Of AjaxControlToolkit.CascadingDropDownNameValue)For iAsInteger = 0To ctable.Count - 1

values.Add(

New CascadingDropDownNameValue(ctable(i).B_NAME, ctable(i).B_NAME))NextReturn values.ToArrayEndFunction

End

Class
I'm having the similar problem. Any new ideas on how to solve it?

There is nothing to do with the number of rows returning from the service. The problem is with your cascadingDropdown declaration.The value for TargetControlID and ParentControlID are given as same, which is causing a recursive call and there by stack overflow.

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server"TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices"ParentControlID="ddl_GetService" >

-Sajid T.K

CascadingDropDown with a Database, Method Error 405

Hey guys,


I followed the AjaxControlToolki tinstructions on how to create a WebService and specify everything so that it would populate two DropDownLists. The problem is, the first DropDownList has a [Method Error 405] as its only value. If I select it, the second DropDownList is populated with the same.

After checking, rechecking and extensively searching, I haven't found my error. I've read at least a dozen topics on this error but none have helped me.

Here is my code:

App_Code/StateServices.cs:

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;

/// <summary>
/// Summary description for StateServices
/// </summary>[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.ScriptService]public class StateServices : System.Web.Services.WebService { GeographicalDelimitationsDB GeoDataSource = new GeographicalDelimitationsDB(); GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter GeoCountyInfoTableAdapter = new GeographicalDelimitationsDBTableAdapters.CountyInfoTableAdapter(); GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter GeoZipCodesTableAdapter = new GeographicalDelimitationsDBTableAdapters.ZipCodesTableAdapter(); public StateServices() { } [WebMethod] public CascadingDropDownNameValue[] GetCounties(string knownCategoryValues, string category) { GeographicalDelimitationsDB.CountyInfoDataTable counties = GeoCountyInfoTableAdapter.GetData(); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (DataRow dr in counties.Rows) { string name = (string)dr["Name"];
int countyID = (int)dr["CountyCode"];

values.Add(new CascadingDropDownNameValue(name, countyID.ToString()));
}

return values.ToArray();
}

[WebMethod]
public CascadingDropDownNameValue[] GetCitiesForCounty(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int countyID;

if (!kv.ContainsKey("County") || !Int32.TryParse(kv["County"], out countyID))
{
return null;
}

GeographicalDelimitationsDB.ZipCodesDataTable cities = GeoZipCodesTableAdapter.GetDataByCountyID(countyID);

List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

foreach (DataRow dr in cities.Rows)
{
values.Add(new CascadingDropDownNameValue((string)dr["City"], dr["ZIP"].ToString()));
}

return values.ToArray();
}
}

 
index.aspx: 

 <asp:UpdatePanel ID="NavigationUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="ConfigurationContentPart" runat="server" CssClass="module-content">
<h3>County:</h3>
<p>
<asp:DropDownList ID="CountyList" runat="server" onchange="selectCounty(this)" />
</p>
<h3>City:</h3>
<p>
<asp:DropDownList ID="CityList" runat="server" onchange="selectCity(this)" />
</p>
</asp:Panel
<ajaxToolkit:CascadingDropDown ID="CountyCascadingDropDown" runat="server" TargetControlID="CountyList" Category="County" PromptText="Select a County" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCounties" />
<ajaxToolkit:CascadingDropDown ID="CityCascadingDropDown" runat="server" TargetControlID="CityList" Category="City" PromptText="Select a City" LoadingText="[Loading...]" ServicePath="StateServices.asmx" ServiceMethod="GetCitiesForCounty" ParentControlID="CountyList" /
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>

Bump...

Please help, I'm really stuck!


Does it work without the onchange handlers on the DropDownLists?

CascadingDropDown SelectedValue Attribute in GridView giving Error

I have a CascadingDropDown inside of an GridView EditItemTemplate. Code is below. I need the SelectedValue of the CascadingDropDown to come from the database when then user Edit's the row. I tried addingSelectedValue='<%# Bind("sentity") %>' but I get this error:

Parser Error Message:The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

Source Error:

Line 67: Line 68: <atlasToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server">Line 69: <atlasToolkit:CascadingDropDownPropertiesLine 70: TargetControlID="ddlEditEntity" Line 71: Category="Entity"

<asp:TemplateFieldHeaderText="Entity">

<EditItemTemplate><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"SelectedValue='<%# Bind("sentity") %>'/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate><ItemStyleHorizontalAlign="Left"Width="20%"/><HeaderStyleHorizontalAlign="Left"/><ItemTemplate><asp:LabelID="lblEntity"runat="server"Text='<%# Bind("sentity") %>'></asp:Label></ItemTemplate></asp:TemplateField>As you've noted, the Toolkit controls don't support data binding yet. (Though we have plans to do so soon!) For the time being, I believe you can override your page's OnDataBind method and set the SelectedValue in code. I think Shawn's posted an example of this to the forum. If that's not enough to get you going, reply back and I'll post a sample.

David, I tried setting the selectedValue for the dropdownlist in theGridView1_RowUpdating method, but it seems to not be working.

GridViewRow row = GridView1.Rows[e.RowIndex];
DataKey datakey = GridView1.DataKeys[e.RowIndex];
// Get hmy for updating the database
int hmy =Convert.ToInt32(datakey.Value.ToString());

if (row !=null)
{
DropDownList ddlEditEntity = row.FindControl("ddlEditEntity")asDropDownList;
DropDownList ddlEditProperty = row.FindControl("ddlEditProperty")asDropDownList;
TextBox txtEditDescription = row.FindControl("txtEditDescription")asTextBox;
TextBox txtEditHours = row.FindControl("txtEditHours")asTextBox;ddlEditEntity.SelectedValue = "Chastain Center (8755)"; // this doesn't seem to be workingstring entity = ddlEditEntity.SelectedItem.Value;string property = ddlEditProperty.SelectedItem.Value;string description = txtEditDescription.Text;decimal hours =Convert.ToDecimal(txtEditHours.Text);int retval =Queries.UpdateEntity(hmy, entity, property, description, hours);

GridView1.EditIndex = -1;

GetTimeByUser(ddlYear.SelectedValue +

"/" + ddlMonth.SelectedValue);

}


Well, we added databinding support in the 60731 release of the Toolkit. :) Would you mind trying that approach again with the updated Toolkit? Failing that, let me know and I'll have a look. For real this time. :) Thanks!


When upgrading to the latest do all I need to do is swap out the dll, correct?


Yes, but you'll need to swap out the Microsoft.Web.Atlas.DLL as well (if you're not already using the July CTP).


Thanks David I will try this approach today. One final question. Is it necessary to swap out the Script Library as well? Do you guys update the JavaScript code to reflect changes in the dll?

I swapped out my dll's as followed:

AtlasControlToolkit.dll (version 1.0.60731.0)

Microsoft.AtlasControlExtender.dll (version 1.0.60726.0)

Microsoft.Web.Atlas.dll (version 2.0.50727.60725)

And did the following and still get the error:

The CascadingDropDownProperties control with a two-way databinding to field sentity must have an ID.

<asp:TemplateFieldHeaderText="Entity"><EditItemTemplate><asp:HiddenFieldID="hdnEditEntity"runat="server"Value='<%# Bind("sentity") %>'/><asp:DropDownListID="ddlEditEntity"runat="server"CssClass="dropDownList"/><atlasToolkit:CascadingDropDownID="CascadingDropDown2"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditEntity"

SelectedValue='<%# Bind("sentity") %>'

Category="Entity"PromptText="<-- Selected an Entity -->"ServicePath="webservices/ws_Timetracking.asmx"ServiceMethod="GetEntitesText"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="ddlEditProperty"ParentControlID="ddlEditEntity"PromptText="<-- Select a Property -->"ServiceMethod="GetPropsForEntitytext"ServicePath="webservices/ws_Timetracking.asmx"Category="Property"/></atlasToolkit:CascadingDropDown></EditItemTemplate>

joee, I've looked into this for some time and discussed the issue with Shawn as well. Unfortunately for your scenario, we're only able to use one-way databinding (i.e., Eval) in Extender Properties declarations. If you want to handle the CascadingDropDown's SelectedValue that comes back from the client, you'll need to do so in code (at least for the time being - fortunately it shouldn't be very much code!). At a very high level, in order to support two-way databinding, ASP.NET looks for a real Control (hence the error you get about needing an ID) and the Extender Properties objects aren't currently Controls themselves.

Sorry for the trouble; I hope this explanation at least makes things clearer.


Hello

I have a CascadingDropDown in a page and need to set its selectedValue based on the values in the querystring. I tried to use the DataBinding event to set the values, but looks like the event is not being raised.

protected void CascadingDropDown1_DataBinding(object sender, EventArgs e)
{
ddMake.SelectedValue = Request.QueryString["make"];
ddModel.SelectedValue = Request.QueryString["model"];
}

Any ideas?

Thanks for the report! I've just fixed this problem for the next Toolkit release with change 3420 in CodePlex:

Method override ExtenderControlBase.OnDataBinding didn't call base.OnDataBinding, so event handlers hooked up to an extender's .DataBinding event weren't getting fired - this change fixes that problem by calling the base class implementation as it should.

If you're able to use the sources from CodePlex, this should work now. Sorry for the trouble!


Thanks David. I guess change 3431 will address my issue as well. Pardon my ignorance, but how do I work off the source code? Do I just need to build and swap out the Web.Atlas and AtlasControlToolkit.dll?
Yes, just download the sources from CodePlex, extract the files somewhere, build the project, and then use the resulting AtlasControlToolkit.dll instead of the one you were formerly using.

So what is the status now regarding to ways binding, e.g. binding a dropdown's selectedvalue to an item in detailsview ?

Wednesday, March 21, 2012

CascadingDropDown Scenario!

Ok heres the deal, go the CascadingDropDown works on a simple aspx page but when I incorporate it into my MasterPages it fails with 12031 error code

Does the page has to derive from Page base class?

TIA

Hi,

Please make sure that the web method used by the cascadingDropDown can't be defined in masterpage, in this case, it can't be accessed from client side directly. Be sure to use a web service.

CascadingDropDown Sample problem, Method Error 500

Hi

I've downloaded the last version of Control Toolkit and I've installed it. When I try to run the WebSampleSite, everything works fine except CascadingDropDown, The first combo says "Method Error 500". Any ideas?

Please help...

to me Method Error 500 is webservices error

try look webservices area..make sure it gets call (you can debug into it)

CascadingDropDown returns [Method Error 12031] after upgrade to 1.0 Beta

After upgrading from the July CTP to 1.0 Beta all my CascadingDropDown's have stoped working. I only get [Method error 12031] in return an all of them. I hade the same problem when implementing them the first time but I then found the answer in thread 1393072 and referenced threads. This time however I am not able to find anything that helps me. I have tried to migrate my July CTP projekt to a new empty 1.0 Beta project but it doesn't help. Have anyone else hade the same problem?

I am grateful for any suggestions and tips!!

Have you made sure to decorate your service class with this attribute?

[Microsoft.Web.Script.Services.ScriptService()]
public class MyService : WebService
{
...
}


Thanks allot!

Now i works just fine. One can wonder why that line isn't in the walkthrough for CascadingDropDown!


Thanks a lot for that! That's been bugging me all morning. Although I didn't have [Method Error 12031], I had [Method Error 500], this solution still worked for me. It really should be in the walkthrough
I Agree! This should be added RIGHT AWAY!!!

Hey Guys,

Actually there is some documentation and I'll point you to where I found most of my upgrade info. Garbin's recent post on his blog has three links to some very vital information.

http://aspadvice.com/blogs/garbin/archive/2006/10/20/MS-AJAX-v1.0-Beta-and-Ajax-Control-Toolkit-released_2100_.aspx

The CTP-to-Beta whitepaper is where I found the not for adding the ScriptService attribute.

Hope this helps.


The method error 12030 still appears for me when I use the CTP and the specified attribute.

Regards

Vinit


Did you change the return type of your methods that populate your drop downs to return an array of AjaxControlToolkit.CascadingDropDownNameValue objects?

All web methods for child drop downs must have a signature that conforms to the following:

[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDataForMyChildDropDown(string knownCategoryValues, string category)

You can find this in the CTP-to-Beta whitepaper I believe.


Hiya.

Had the same problem and finally found out why. None of the other things suggested worked. Thanks to Steve Clements for that one... http://geekswithblogs.net/steveclements/archive/2006/10/23/94893.aspx

The web service class either needs

[Microsoft.Web.Script.Services.ScriptService]

or

using Microsoft.Web.Script.Services;

namespace Clm.Web.Services

{

[ScriptService]

publicclassFoo


Your most welcome :)

Steve


Same problem, but using only pagemethods...

What changes do I need to get it working?


Can you post some code?
http://forums.asp.net/thread/1486194.aspx

Hi,

I've run into the same error. However, when I change the line in the webservice.vb file from:

<System.Web.Script.Services.ScriptService ()>'

to:

<Microsoft.Web.Script.Serices.ScriptService ()
I get the error 'Type Microsoft.Web.Script.Serices.ScriptService' is not defined'

The whole "snippet":

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class CarsService
Inherits System.Web.Services.WebService

Shared _DocumentAs XmlDocument
Shared _lockAs New Object

I'd appreciate any suggestions.
Thanks!

CascadingDropDown require EventVlidation=false?

I turned on event validation (=true) of the Atlas Control Toolkit sample -> CascadingDropDown .

When I click the , Error message suggest turn event validation off.

Is this a must?

I saw some thread showing that they can add an attribute "SuppressEventValidation", but I can't see smart tag/ code hints in my version? Is it a new feature in later built of atlas?

Please advice how to keep EventValidated ?

This thread explains why I believe EnableEventValidation needs to be false:http://forums.asp.net/thread/1281139.aspx

Thanks for your kindly reference, It's really a time for me to choose between SECURITY , USABLITILY

I need to sacrifice security , choose usablitiliy

CascadingDropDown Problem

Hi All

I'm using the latest release of the toolkit. I'm building a CascadingDropDown and am getting a 12030 method error when I use a remote service (rather than have the service in the same project).

<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlMake" Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]" ServicePath="~/../CarServiceLocal/CarService.asmx" ServiceMethod="GetDropDownContents"/>

If I set the Service path to a local asmx file it works fine ServicePath="CarService.asmx"

But if I change it to be a remote service

ServicePath="~/../CarServiceLocal/CarService.asmx"

or

ServicePath="http://localhost/CarServiceLocal/CarService.asmx"

Then I get the 12030 method error.

Does anyone have any ideas?

Cheers


Craig

The CDD sample page uses the ~ syntax, so I'm reasonably confident it works in general. Your use of it with ".." makes me wonder if it works like you think it does. I'd say to double-check that the final path that gets used is correct.

CascadingDropDown Problem

Hello everyone,

I'll try to keep it simple and brief. This is another "[Method Error 500]" problem. I looked through all previous posts, but couldn't figure out the solution to my problem.

I'm using AJAX 1.0 RC and the latest version of the Control Toolkit (downloaded yesterday).
I have 3 dropdownlists. Here's how it goes:

1) I select something from DDL1 (DDL2 becomes populated)
2) I select something from DDL2 (DDL3 becomes populated)

until this point everything is OK. BUT, in DDL2, there is aparticularitem that when I select it, DDL3 says "Method Error 500". Other than that particular item, it all works fine.

Notes:
1) My Webservice declaration has the attribute[System.Web.Script.Services.ScriptService()]
2) I debugged the code, the results for this particular problem are returned from the database just fine, no exceptions, no problems.

Any ideas, tips?

Thanks!

This, perhaps:http://ajax.asp.net/docs/mref/P_System_Web_Script_Serialization_JavaScriptSerializer_MaxJsonLength.aspx

Yes! Thanks

(http://forums.asp.net/thread/1553105.aspx)

CascadingDropDown placed inside an asp:EditItemTemplate.

I tried the cascading dropdownlist when the user clicks on edit on a formview, but I realized from the following error that this will not work:

System.InvalidOperationException: The UpdatePanel 'EditUpdatePanel' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template.

I also found a previous threadhttp://forums.asp.net/thread/1255759.aspxwhere the respondent confirmed that the updatePanel must be outside of the GridView

Does that mean that theAtlasControlToolkit:cascadingdropdown control cannot be used within any databound templated controls (such as GridView, FormView, Details, etc.)?

I don't believe so. UpdatePanel has "special needs" on the page which is why it probably has this issue. I haven't tried this but I think CascadingDropdownshould work OK - I can't think of why it wouldn't. Can you give it a try and report back?


I think the problem is that theatlasToolkit:CascadingDropDown requires anatlas:UpdatePanel around the dropdownlists otherwise changing the selection in one dropdownlist would not affect the next. But sinceatlas:UpdatePanel cannot be placed within the EditItemTemplate therefore it seems that there is no way to put theatlasToolkit:CascadingDropDown within the EditItemTemplate.

Here I tried 3 scenarios in addition to the one I described in my previous post:

1- The cascadingdropdown lists work if placed within atlas:UpdatePanel outside of an EditItemTemplate:http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown.aspx

2- The cascadingdropdown lists not working if placed within the EditItemTemplate and the atlas:UpdatePanel outside the FormView. http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown2.aspx

(On my local PC, a JavaScript popup dialog box comes with the following error: "System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page." But when run remotely you do not get that error. The lists just do not display anything)

3- The cascadingdropdown lists not working if placed within the EditItemTemplate and no atlas:UpdatePanel on the page

The source code for all scenario are listed on the demo pages.


CascadingDropDown does not need an UpdatePanel to work - the client-side changes are done in script and the web service requests are async thanks to Atlas. So #3 above is the scerario you probably want. I suspect it's not working for you because your ParentControlID properties are pointing at "CascadingDropDownX", but your DropDown controls are named "ddlYYY". Please try fixing that and let us know how it goes!

Hi David,

Thanks for your help. Your suspicion was right. I had the wrong values for the ParentControlID. Now that I corrected them and got it working within the FormView's EditItemTemplate and the data is being updated upon postback successfuly as shown here: http://www.webswapp.com/codesamples/aspnet20/atlas/toolkit_cascadingdropdown.aspx

I am wondering about the possibility of doing 2 more features to make the function of this control equivalent to the server-side controls:

1- How to set the default values upon loading the EditItemTemplate? (Since I could not use the Bind or Eval statements)

2- In order to prevent flashing of the screen when I submit the FormView, I tried using the Atlas:UpdatePanel around the FormView but I got this error message:

Assertion Failed: Unrecognized tag AtlasControlExtender:ValidationScript


That is so cool!

From above...

1) This is a feature we've added to the refresh, which should be available within the next day or so. When it is, you can just add a "SelectedValue='blah'" to the properties and it'll select that value

2) I'm not sure why you're getting that. In any case, in your extender set "SuppressValidationScript='false'" and it'll preven that guy from even loading.


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

I tried # 2 above but I still get the error. The code is exactly as listed in the link I provided before plus the updatePanel surrounding the FormView

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

<ContentTemplate>

<asp:FormViewID="FormView1"runat="server" .... >

</asp:FormView>

</ContentTemplate>

</atlas:UpdatePanel>


SuppressValidationScript="true"

Ok. The first error (above) does not show up but the next errors (which used to appear after I clicked on cancel) is still repeated for each dropdown list: "Assertion Failed: Unrecognized tag atlasControlToolkit:cascadingDropDownBehavior"


That's often related to the relative position of the controls, the extender, and the UpdatePanel. Some wiggling around of the different items can sometimes solve the problem. If it doesn't - and if the new Toolkit release doesn't help - please let us know.