Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 3.5 Website Programming Problem Design Solution
This is the forum to discuss the Wrox book ASP.NET 3.5 Website Programming Problem Design Solution by Chris Love; ISBN: 978-0-470-18758-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Website Programming Problem Design Solution section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #31 (permalink)  
Old June 21st, 2010, 10:13 PM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Seems like it's probably better not to use Masterpage when using JQuery!
  #32 (permalink)  
Old June 22nd, 2010, 01:58 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

No, i don't think that's the right conclusion. For stuff that needs to run on all or most pages, putting jQuery code in the Master Page makes a lot of sense. However, you need to be aware of the issue with the changed IDs. One way around this is to use class selectors in jQuery as opposed to ID selectors.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #33 (permalink)  
Old June 24th, 2010, 10:02 PM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi,

I created the third dropdown list, but it's blank now. Why is it not getting populated? I'm not using the Masterpage, just default.aspx and I updated pretty much everything else accordingly. New functions I added, for example...

--- function loadEmployeeCarColors(selectedItem) {
$.ajax({
type: "POST",
url: "Default.aspx/FetchEmployeeCarColors",
data: "{id: " + selectedItem + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function Success(data) {
printEmployeeCars(data.d);
}
});
}

function printEmployeeCarColors(data) {
$("select[name$=ddlEmployeeCarColors] > option").remove();
for (var i = 0; i < data.length; i++) {
$("select[name$=ddlEmployeeCarColors]").append(
$("<option></option>").val(data[i].Id).html(data[i].Car)
);
}
}
...

In the page_load, I have added...

---

var employees = new Employee();
var employeeCars = new EmployeeCar();
var employeeCarColors = new EmployeeCarColor();
ddlEmployee.DataSource = employees.FetchEmployees();
ddlEmployee.DataTextField = "Surname";
ddlEmployee.DataValueField = "Id";
ddlEmployee.DataBind();
---

I also added a class called EmployeeCarColor.cs with usual stuffs.

What could've gone wrong?
  #34 (permalink)  
Old June 25th, 2010, 04:41 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Hard to tell without seeing how it all fits together. Have you tried debugging in Visual Studio? You should be able to "follow the wire" and find out if the right code is called and whether or not the right data gets passed back to the client.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #35 (permalink)  
Old June 29th, 2010, 09:28 PM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Ok, let's consider a scenario for third dropdown list driven from a database.

It's different data - here it's CarName, models and colors


For second dropdown I have a webservice [WebMethod] in CarsService.cs

Code:
    [WebMethod]
    public CascadingDropDownNameValue[] GetModelsByCarId(string knownCategoryValues,
        string category)
    {
        // Split the knownCategoryValues on ":" with ";" delimiter 
        // For the first dropdownlist, the values will be "undefined: id of the dropdownelement"
        // ex: "undefined: 13;"
        // The string at index 1 will be the CarId selected in the dropdownlist.
        string[] _categoryValues = knownCategoryValues.Split(':', ';');
        // Convert the element at index 1 in the string[] to get the CarId
        int _carID = Convert.ToInt32(_categoryValues[1]);
        // Create a List<T> of CascadingDropDownNameValue to hold the CarModels data
        List<CascadingDropDownNameValue> _carModels = new List<CascadingDropDownNameValue>();
        // Create an instance of CarModels TableAdapter
        dsCarModelsTableAdapters.CarModelsTableAdapter _carModelAdapter = new dsCarModelsTableAdapters.CarModelsTableAdapter();
        // For each datarow in the DataTable returned by the GetModelsByCarId method, add the modelname and modelid to the List<T>
        foreach (DataRow _row in _carModelAdapter.GetModelsByCarId(_carID))
        {
            _carModels.Add(new CascadingDropDownNameValue(_row["ModelName"].ToString(), _row["ModelId"].ToString()));
        }
        // convert to array and return the vlaues
        return _carModels.ToArray();
    }
now, if I create a [WebMethod] for third dropdown right underneath as:

//This is the third dropdown for
// getColorbymodelId
[WebMethod]
public CascadingDropDownNameValue[] GetColorsByModelId(string knownCategoryValues,
string category)
{
// Split the knownCategoryValues on ":" with ";" delimiter
// For the first dropdownlist, the values will be "undefined: id of the dropdownelement"
// ex: "undefined: 13;"
// The string at index 1 will be the CarId selected in the dropdownlist.
string[] _categoryValues = knownCategoryValues.Split(':', ';');
// Convert the element at index 1 in the string[] to get the CarId
int _modelID = Convert.ToInt32(_categoryValues[1]);
// Create a List<T> of CascadingDropDownNameValue to hold the CarColorss data
List<CascadingDropDownNameValue> _carColors = new List<CascadingDropDownNameValue>();
// Create an instance of CarColors TableAdapter
dsCarColorsTableAdapters.CarColorsTableAdapter _carColorAdapter = new dsCarColorsTableAdapters.CarColorsTableAdapter();
// For each datarow in the DataTable returned by the GetModelsByCarId method, add the modelname and modelid to the List<T>
foreach (DataRow _row in _carColorAdapter.GetColorsByModelId(_modelID))
{
_carColors.Add(new CascadingDropDownNameValue(_row["ColorName"].ToString(), _row["ColorId"].ToString()));
}
// convert to array and return the vlaues
return _carColors.ToArray();
}

I get the following two errors:

Error 86 The type or namespace name 'dsCarColorsTableAdapters' could not be found (are you missing a using directive or an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 9 http://localhost/WebSiteDDL1/

Error 87 The type or namespace name 'dsCarColorsTableAdapters' could not be found (are you missing a using directive or an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 79 http://localhost/WebSiteDDL1/


>> why does the same work for CarModels, but, not the car colors(3rd dropdown)
  #36 (permalink)  
Old June 30th, 2010, 02:28 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

The error about 'dsCarColorsTableAdapters' seems to suggest that you haven't added this adapter to your typed data set definitions? Where is dsCarModelsTableAdapters defined? That's where you also need to define dsCarColorsTableAdapters...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #37 (permalink)  
Old July 1st, 2010, 04:19 AM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

That's exactly what I had the impression at first. But, the problem is that dsCarModelsTableAdapter is only defined in the

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\websiteddl1\3091bb51\5ea88914\Sources_App_Co de\dscarmodels.xsd.72cecc2a.cs

That's kind of assembly file and I can't possibly add dsColor table Adapters there!

Here's the original article. He doesn't quite mention how to add TableAdapters in the article:

http://aspalliance.com/1183_Creating...Using_AJAX.all
  #38 (permalink)  
Old July 1st, 2010, 04:28 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

That assembly is generated based on the information for the typed datasets. You need to add another dataset yourself by following the steps in the section "Creating the datasets for accessing the Cars and CarModels data".

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #39 (permalink)  
Old July 1st, 2010, 05:25 PM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

The tableAdapter was already created, so was the dataset. Fail to understand why it doesn't see it!
  #40 (permalink)  
Old July 1st, 2010, 05:32 PM
Authorized User
 
Join Date: Apr 2010
Location: Seattle, WA
Posts: 50
Thanks: 3
Thanked 0 Times in 0 Posts
Default

So after deleting the previously created and recreated the steps. Now, I get a different error message on the following code:

<code>
dsCarColorsTableAdapters.CarColorsTableAdapter _carColorAdapter = new dsCarColorsTableAdapters.CarColorsTableAdapter();
</code>

Error 55 The type or namespace name 'CarColorsTableAdapter' does not exist in the namespace 'dsCarColorsTableAdapters' (are you missing an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 34 http://localhost/WebSiteDDL1/
---
Error 56 The type or namespace name 'CarColorsTableAdapter' does not exist in the namespace 'dsCarColorsTableAdapters' (are you missing an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 104 http://localhost/WebSiteDDL1/
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown list maha .NET Framework 2.0 7 April 28th, 2007 12:32 AM
Dropdown list with multiple selections tombert ASP.NET 1.0 and 1.1 Basics 15 March 7th, 2007 07:38 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
Storing multiple values from the dropdown list lily611 SQL Server 2000 0 June 21st, 2004 06:08 AM
Storing multiple values from the dropdown list lily611 ADO.NET 0 June 21st, 2004 05:21 AM



All times are GMT -4. The time now is 01:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.