Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Monday, March 26, 2012

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)

Saturday, March 24, 2012

CascadingDropDownList problem !

Hi there, I'm in trouble with cascadingDropDownList extender.

I use webMethod to make connection to a SQL database, actually methods work fine and get results in XML form in test page. However, when I make call from the cascadingDropDownLists at the .aspx page, It only gets a "Method error 500"

Here is the code

---.ASPX---

<%@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"/>

<div>

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

</asp:DropDownList>

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

</asp:DropDownList>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="DropDownList1"

Category="MarkaTitle"

ServicePath="http://localhost:3631/CDDWebService/Service.asmx"

LoadingText="Please Wait..."

PromptText="Select a Marka..."

ServiceMethod="getMarka">

</atlasToolkit:CascadingDropDownProperties>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="DropDownList2"

Category="ModelTitle"

ServicePath="http://localhost:3631/CDDWebService/Service.asmx"

ParentControlID="DropDownList1"

ServiceMethod="getModel"

PromptText="Select Model..."

LoadingText="Please Wait...">

</atlasToolkit:CascadingDropDownProperties>

</atlasToolkit:CascadingDropDown>

</div>

</form>

<scripttype="text/xml-script">

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

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

/---.ASPX---

--WebService Codes--

using System;

using System.Web;

using System.Web.Services;

using System.Configuration;

using System.Web.Services.Protocols;

using AtlasControlToolkit;

using System.Collections;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Data;

using System.Data.SqlClient;

[WebService(Namespace ="http://Boss.com.tr/",Name="CDDWS")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassService : System.Web.Services.WebService

{

string myConnectionString =ConfigurationManager.ConnectionStrings["VehiclesConnectionString"].ToString();

public Service () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

publicCascadingDropDownNameValue[] getMarka(string knownCategoryValues,string category)

{

SqlConnection dbConnection =newSqlConnection(myConnectionString);

SqlDataAdapter myAdapter =newSqlDataAdapter("select * from MarkaTbl", dbConnection);

DataTable myTable =newDataTable();

try

{

myAdapter.Fill(myTable);

}

catch (Exception ex)

{

//throw ArgumentException("not valid");

}

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

foreach (DataRow drin myTable.Rows)

{

values.Add(newCascadingDropDownNameValue((string)dr["MarkaTitle"],dr["MarkaID"].ToString()));

}

return values.ToArray();

}

[WebMethod]

publicCascadingDropDownNameValue[] getModel(string knownCategoryValues,string category)

{

SqlConnection dbConnection =newSqlConnection(myConnectionString);

SqlDataAdapter myAdapter =newSqlDataAdapter("select * from ModelTbl", dbConnection);

DataTable myTable =newDataTable();

try

{

myAdapter.Fill(myTable);

}

catch (Exception ex)

{

}

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

foreach (DataRow drin myTable.Rows)

{

values.Add(newCascadingDropDownNameValue((string)dr["ModelTitle"], dr["ModelID"].ToString()));

}

return values.ToArray();

}

}

/--WebService Codes--

One more question; I couldn't understand exactly what is "category", and what it is stands for. I considered it is as fieldName of at the database :)

Thanks for any help ...

At least, can someone tell me what is "category" in CascadingDropDown extender ?

Hi BossDida,

You're getting a message returned by the ASP.NET AJAX Extensions indicating "there was a problem with your web service." I'd take a look at the CascadingDropDown.aspx sample page to see how what you're doing differs from it.

Also, the category (as described in the CascadingDropDown sample page) is used to indicate to the web service which drop down is asking for data (because you can have all your drop downs hit the same webmethod if you wanted).

Thanks,
Ted

CascadingDropDown using SQL in VB example anyone?

I'm new to using the AjaxControlToolkit, and I'm finding lots of variations in the examples out there. I would like to use the CascadingDropDown control to populate a State, and Country drop down. I am using ASP 2.0, and I'm developing code using Visual Web Developer 2005 Express. The data files reside on a separate SQL 2000 server.

Does anyone have a good example out there? All of the tutorial videos either use an XML file for the data, or have tags that are no longer supported in the latest tool kit (like CascadingDropDownProperties).

I had the same problem with the Ajax Tab controls (lots of different versions), but figured that one out. Not finding much on the web.

Any help would be greatly appreciated.

Hi and welcome to the forums.

Have you checked this tutorial.http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/CCDWithDB.aspx. Though this is in C#, it is very simple. Try to convert it yourself or else try this tool to convert from C# code to VBhttp://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx. If you still have problems, then post it here and we will convert it.

All the best.


Yes, I've viewed that video. What would I have to change to make the example in this video point to SQL tables? Or, If I convert my Country table, and State table to one XML file, how would I handle countries with no states?

I would really like to find an example that uses the current Ajax Control Toolkit for ASP.Net 2.0 that uses SQL tables. In the meantime, I'll try and make the example work with my own XML Country/State data.

Thanks.

Wednesday, March 21, 2012

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