Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Monday, March 26, 2012

Exporting GridView Values to Excel...

Hey... i get this error when i am exporting a gridview to a excel file. I know that is something with AJAX...

sys.webForm.PageRequstManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are the response is modified by calls to response.write(), response filters, http modules or server trace is enable.

Tongue Tied

You can't use the Response object to write a file directly back on a partial postback's response. That's the source of your error.

However, you canuse an iframe to simulate an AJAX file download.


hello.

just to add a link to my post about that subject:

http://msmvps.com/blogs/luisabreu/archive/2007/10/17/asp-net-ajax-some-ideas-on-how-to-export-the-contents-of-a-gridview-to-an-excel-file-without-a-full-postback.aspx

Execute JS Code onload and on partial postback

Hi All,

I have a ScriptManager tag that contains a script reference to a JS file; "test.js." Test.js contains a function that needs to be executed on the application's loadand on a partial postback.

The reason that it needs to be executed on the application's load event is because if I execute it just using RegisterStartupScripts the script isn't present on the page yet because it is being controlled by Atlas.

So, I create a wrapper function for statement on the fly and I register it to execute on the application's load event. I.e. "Sys.Application.load.add(wrapperFunction);"

That works great the first time through when the page is loaded because the application's load event fires. However, how do I get the same execute statement to fire on a partial postback? The only workaround I have right now is to get a handle to the current ScriptManager and test to see if it is InPartialRenderingMode. If so, I don't do the add to load code, but I just register a startup script instead.

Is there a nicer, easier, cleaner way of doing this.

Thx!!Hi,

I think I have a decent workaround for the moment. My example I was providing was a bit simplistic in comparison with what I actually need to do. I actually needed to completely change what JavaScript commands were executed and their parameters for each time a server side control was loaded. Having said that, the best way I've come up with so far is test on the backend if my ScriptManager is in PartialRenderingMode and handle it accordingly. If it isn't, I use the load event and attach a delegate to execute. If it is, I just execute a the function that was to be the delegate. It's not the prettiest code, but it works reliably and can be repeated for other controls.

Thanks for your help on this.

I need to do the same thing. How did you get it done?

I have a myfuncs.js in the script manager.

I want to call a function in the js file after a updatepanel psotback.

I can not find a good way to fire it. I thought Application.Load would do it but the page only gets loaded once.

and ideas?


I kind of do what I described a few posts back.

I test to see if the control's ScriptManager is in PartialRenderingMode and if so, I just emit the JavaScript straight to the client using the ClientScriptManager.RegisterStartupScript method. If it is not in PartialRenderingMode, I wrap my JavaScript in a function and add it to the Sys.Application.load event and then emit the whole code block to the client again using the RegsiterStartupScript method.

Ex of what it would look like on the client.

function WrappedFunction() {
var x = new Array();
x.push(1);
}

Sys.Application.load.add(WrappedFunction);

OR

var x = new Array();
x.push(1);

HTH

hello.

since the file is already loaded, how about adding an event handler to the propertychanged event and check? there you could check the property that's changedand if it's the inPostBack property and its value is false, you know that you've just finished loading the page. btw, why can't you use the registerstartupscript method? i don't understand what you mean when you say that the script is being controlled by atlas...


Hi.

By "script is being controlled by atlas" I mean that the script file is registered with the ScriptManager.

I.e.
<atlas:ScriptManager ...>
<scripts>
<atlas:ScriptReference path="test.js" ...>
</ ..>
</..
The reason that the script needs to be registered with Atlas is that the function I need to execute on startup and postback has code within it that relies upon the Atlas Sys namespace and therefore must be loaded after the Atlas scripts have been loaded otherwise it'll throw an error complaining it doesn't know what Sys is. (The statement also relies on user input which is the reason it needs to get reexecuted on postback.)

It is my understanding that the page processes any <script ...> tags including any startup scripts first; then loads the Atlas scripts; then loads the scripts that are defined within the ScriptManager Scripts tag.

So, if I just use the RegisterStartupScript method and my scripts are registered with the ScriptManager, my startup statement will execute before the Atlas files (and my custom js file) have been loaded and throw an exception. My code needs to wait for the Atlas files and my custom js file to load before executing so instead, I add the startup statement to a function and add it to the Sys.Application.load event delegate as an event handler. This way it'll wait until Atlas has loaded before executing.

This works fine for the load, but one of the function's parameters is based upon user input and the function needs to be reexecuted whenever the page is postbacked.

The first time through the code looks like

function wrapperFunction () { testFunction (''); }
Sys.Application.load.add (wrapperFunction);

But, on postback the same part of the code would look like

function wrapperFunction () { testFunction('30111'); }
Sys.Application.load.add (wrapperFunction);

Of course, the second code block doesn't do anything on postback because the load event has already fired. To accomplish the same thing on postback the code would just look like:

testFunction ('30111');

as the test.js file where testFunction lives has already been registered and now can be accessed through startup scripts.

(All code blocks are registered to execute on startup.)

I'm not really seeing how I can do what you suggested and add an event to the PageRequestManager as my function call needs to change based upon user input.

So I can test for InPartialRenderingMode in code behind and modify the startup JavaScript accordingly (which is what I'm currently doing), but it seems that there needs to be an event that covers both loading initially and loading after a postback. Emitting a pure JavaScript function call works for postbacks and attaching to the load event of the Application works for loading initially, but I'd like to be able to write one piece of code that works for both cases.

Phew ... I hope that's at least partially clear.

Thx for any and all help.

hello.

yes, now i understand.

handling the propertychanged of the pagerequestmanager is the only way i know to handle the end of partial postback.

what you could do is inject a global variable with the value that you need to pass to your jscript function; since the registerXXX inserted method will be called before the event being fired, you can be sure that the global variable will allways be correctly set up.


To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal
To call specific javascript function or register a new javascript after the update panel partial postback

you can use my custom made control

to download it and to know how to use it

visit my blog.

http://go2amitech.blogspot.com/2010/08/running-specific-javascript-after.html[^]



Amit Panchal

Saturday, March 24, 2012

Exclude are from UpdatePanel

Is there a way to exclude an area from the UpdatePanel?

I ask because I have a usercontrol that has a StepWizard and one of the steps has a file upload. The page that contains the usercontrol has an UpdatePanel that wraps the usercontrol.

The same issue + suggestion ishere.

"I made something named PopupCallback feature for popups calling a server side method on it's opener."

Could you elaborate on this? I'm not really sure what you are doing.

I can't believe this ability wasn't built in to Atlas...hopefully future versions will look at this.


Well you probably have been into the scenario where you have this "Oh crap, I saved something in my popup, now I want the opener page to rebind is grid, to show that the changes were reflected!"
And this should be done without any nasty hacks like window.opener.document.getElementById("fuglyHack").click();

So what I did was to make something a bit more elegant:

First off, I should make it a singleton control that has to exist on Page (like ScriptManager), now I have it embedded in the actual page:

using System;using System.Text;using System.Collections;using System.Collections.Generic;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace SomeMysticCompany.Web.SomeWebProject.SiteCore{/// <summary> /// Summary description for BasePage /// </summary>public abstract class BasePage : System.Web.UI.Page, IPostBackEventHandler {private static readonly object EventCommand =new object();public event CommandEventHandler PopUpCallback { add {base.Events.AddHandler( EventCommand,value ); } remove {base.Events.RemoveHandler( EventCommand,value ); } }protected override void OnPreRender( EventArgs e ) {this.Page.ClientScript.RegisterClientScriptBlock(typeof( Page ),"PopUpCallback","function BasePage_PopupPostBack( argument ) { __doPostBack('__Page', argument); }",true );base.OnPreRender( e ); }public void SetCloseScript() {this.ClientScript.RegisterStartupScript(typeof( Page ),"close","window.close();",true ); }public void SetPopupCallbackScript(string commandName,params object[] arguments ) {this.ClientScript.RegisterStartupScript(typeof( Page ),string.Format("PopupCallback_{0}", commandName ),this.GetPopupPostBackReference( commandName, arguments ),true ); }public string GetPopupPostBackReference(string commandName,params object[] arguments ) {object[] data =new object[ 2 ]; data[ 0 ] = commandName; data[ 1 ] = arguments;return string.Format("window.opener.BasePage_PopupPostBack('{0}');", Server.HtmlEncode( Util.GetBase64String( data ) ) ); }#region IPostBackEventHandler Memberspublic void RaisePostBackEvent(string eventArgument ) { CommandEventHandler handler =base.Events[ EventCommand ]as CommandEventHandler;if ( handler ==null )return;object[] data = Util.GetDataByBase64ObjectString( Server.HtmlDecode( eventArgument ) )as object[];if ( data ==null )return; CommandEventArgs args =new CommandEventArgs( data[ 0 ]as string, ( data.Length > 1 ) ? data[ 1 ] :null ); handler(this, args ); }#endregion }}

That's the first piece of code. Now, to get a reference to create a popup callback script you just call
"SetPopupCallbackScript", or just use "GetPopupPostBackReference" if you want it on a client click or something.

Now, the interesting part is the server side HANDLER of the callback... what happens is that when you execute the script returned from these methods, you will set a serialized object array on the window.opener and submit.
The only thing you need to do is to hook up to the event exposed:

// Some user control or whateverprotected override void OnInit( EventArgs e ){this.Page.PopUpCallback +=new CommandEventHandler( Page_PopUpCallback );base.OnInit( e );}private void Page_PopUpCallback(object sender, CommandEventArgs e ){if ( e.CommandName !="GetData" )return;this.LoadData();}
This will call "LoadData" if you have the popup executing the script:
// In popup, actually outputting script to raise event on openerprivate void Finish(){this.Page.SetPopupCallbackScript("GetData" );}
Is this clear to you? This provides a bit more clean way to pass data without losing it's integrity.
Sorry, referencing this.Page instead of base is just stupid, I am just so used to doing that, replace it!

I'll have to take some time to look it over. I'm actually trying to exclude a file upload control from a step wizard. I don't usually code at this level but I think I see how it's working.

Thanks for working with me!

exception when work with ajax update panel animation extender

hi

i put ajax update panel animation extender and request for the .cs file for debuggging means that there is exception

does i need to set something for this control to make it work?

thanks in advance.

any help


no answers


Hi seco,

Would you mind sharing your source code here?


thanks for reply

i just drag update panel animation extender and specify the control id to be my update panel nothing more ..

so.any thing else to do ?

thanks.


I'm afraid that I cannot figure out the issue.Would you please do some simple tests ?

1. Use the other ControlToolkit Controls to see whether all the Controls have the same problem or not.

2. Test the UpdatePanelAnimation sample provided by Ajax ControlToolkit in your environment to confirm whether it works fine or not.

Download from : http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=4923

3. If I works , please focus on your source code(compare with the sample). Otherwise , please reinstall your Asp.Net Ajax Extension and Ajax Control Toolkit. Then , have a test.

Hope it helps.

Exception During Exporting Data From GridView to Excel File

Hi ,

I am Using Update Panel in my page and this Update panel contains lots of server side controls including GridView ...

Well, i want to Export Data from GridView to Excel or PDF file ... But its not working properly ...

The Code is ...

Response.Clear();

Response.AddHeader("content-disposition","attachement;filename=" +"IFR" + System.DateTime.Now +".xls");

Response.Charset ="";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType ="application/vnd.xls";

StringWriter stringWrite =newStringWriter();

HtmlTextWriter htmlWrite =newHtmlTextWriter(stringWrite);

gvReport.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

The code written is correct but it gives Exception on Execeting the line.. gvReport.RenderControl(htmlWrite);

Exception = < Control 'gvReport' of type 'GridView' must be placed inside a form tag with runat=server. >

And all the controls including GridView are inside the form tag.

Please Help me out to fix that problem i shall be very thankful 2 u.

Its gud if u reply the solution on ... irfan623@dotnet.itags.org.hotmail.com

Thanks .

Irfan Gull

Hi There,

You can't use Response.Write inside of an UpdatePanel.

Why? Because Ajax updates are done using XMLHttpRequest which exchanges xml with server. Resonse.Write adds some string in xml and the xml parser on the client has no idea what to do with such a xml.

Hope it helps!


Basically the Error is at

dgFailureReport.RenderControl(htmlWrite);

When this line executes than Exception occurs...

There is no problem with response.write ...

the problem is with only the above one line code...

Let me paste the code again here... am still having that problem please someone help me ragarding this... thanks in advance...

Response.Clear();

Response.AddHeader("Internal Failure Report","attachement;filename=" +"IFR" + System.DateTime.Now+".xls");

Response.Charset ="";

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType ="application/vnd.xls";

StringWriter stringWrite =newStringWriter();HtmlTextWriter htmlWrite =newHtmlTextWriter(stringWrite);

dgFailureReport.RenderControl(htmlWrite); // Here Exception Occurs.

Response.Write(stringWrite.ToString());

Response.End();

Example cssfile for Tab Control ?

Does anyone have an example css file or a definition of what fields control what on the control.

Every post on this subject, including the Ajax Control Toilkit samples points to the link below, which does not work anymore. (I contacted the company but no reply so far).

....or does anyone have a copy of this blog ??

http://community.bennettadelson.com/blogs/rbuckton/archive/2007/02/02/Skinning-model-for-Calendar-and-Tabs-in-Ajax-Control-Toolkit.aspx

Thanks for any help.

KeithT

Hi Keith,

May be you can download the source file for the Control Toolkit, and a full list is available in the /tabs/Tabs.css file.

Hope this helps.


Thanks Raymond,

The example file in the source is a useful start.

For people doing this don't forget to override the .ajax__tab_xp default in both the tab container and the tab panels, otherwise the styles are not applied.

Regards

KeithT


Hello Keith,

Could please explain how to override the .ajax__tab_xp class.

Also, does anyone know how the Tab styles are applied once I add the Tab.css to my Themes folder.

Thanks


Look, this is the default css for tabs:

/* default layout */.ajax__tab_default .ajax__tab_header {white-space:nowrap;}.ajax__tab_default .ajax__tab_outer {display:-moz-inline-box;display:inline-block}.ajax__tab_default .ajax__tab_inner {display:-moz-inline-box;display:inline-block}.ajax__tab_default .ajax__tab_tab {margin-right:4px;overflow:hidden;text-align:center;cursor:pointer;display:-moz-inline-box;display:inline-block}/* xp theme */.ajax__tab_xp .ajax__tab_header {font-family:verdana,tahoma,helvetica;font-size:11px;background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-line.gif")%>) repeat-x bottom;}.ajax__tab_xp .ajax__tab_outer {padding-right:4px;background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-right.gif")%>) no-repeat right;height:21px;}.ajax__tab_xp .ajax__tab_inner {padding-left:3px;background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-left.gif")%>) no-repeat;}.ajax__tab_xp .ajax__tab_tab {height:13px;padding:4px;margin:0;background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab.gif")%>) repeat-x;}.ajax__tab_xp .ajax__tab_hover .ajax__tab_outer {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-hover-right.gif")%>) no-repeat right;}.ajax__tab_xp .ajax__tab_hover .ajax__tab_inner {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-hover-left.gif")%>) no-repeat;}.ajax__tab_xp .ajax__tab_hover .ajax__tab_tab {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-hover.gif")%>) repeat-x;}.ajax__tab_xp .ajax__tab_active .ajax__tab_outer {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-active-right.gif")%>) no-repeat right;}.ajax__tab_xp .ajax__tab_active .ajax__tab_inner {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-active-left.gif")%>) no-repeat;}.ajax__tab_xp .ajax__tab_active .ajax__tab_tab {background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-active.gif")%>) repeat-x;}.ajax__tab_xp .ajax__tab_body {font-family:verdana,tahoma,helvetica;font-size:10pt;border:1px solid #999999;border-top:0;padding:8px;background-color:#ffffff;}/* scrolling */.ajax__scroll_horiz {overflow-x:scroll;}.ajax__scroll_vert {overflow-y:scroll;}.ajax__scroll_both {overflow:scroll}.ajax__scroll_auto {overflow:auto}


Is a file that you can get from the AjaxControlToolkit\Tabs (where you instaled ASP AJAX Extensions). Also, you can get there all the images that the default theming uses.

So, you just need to changecopy that code in your page CSS sheet and change "ajax__tab_xp" for "myCustomstyle", and put into TabContainer properties CSsClass=myCustomstyle.

Notice that for the background image url is using<%=WebResource("AjaxControlToolkit.Tabs.tab-right.gif")%>, so you have to change this to your images path.

Hope it helps

Wednesday, March 21, 2012

Error25Could not load file or assembly Microsoft.Web.Extensions, Version=1.0.61025.0, Cult

Hi there,

I am just trying to learn AJAX at the moment and have run into a problem. I have copied over the example for cascading dropdowns and this is where I have the above error.
The error occurs in the web.config file on this line

<

addassembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

Can anyone advise what I need to change?

The sample is for old ajax version.

you need to copy latest ASP.NET AJAX web.config to your projects web.config

below is my cascading code for new version for you

ASPX

<%@. Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="CascadingDropDownDemo._Default" EnableEventValidation="false" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!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="sm" runat="server">
</asp:ScriptManager>
<div>

<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddl1" runat="server" Width="275px">
</asp:DropDownList><br />
<asp:DropDownList ID="ddl2" runat="server" Width="275px">
</asp:DropDownList><br />
<asp:DropDownList ID="ddl3" runat="server" Width="275px">
</asp:DropDownList><br />
<cc1:CascadingDropDown ID="ccd1" runat="server" TargetControlID="ddl1" Category="Make"
PromptText="Please select a make" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="ccd2" runat="server" TargetControlID="ddl2" Category="Model"
PromptText="Please select a model" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"
ParentControlID="ddl1">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="ccd3" runat="server" TargetControlID="ddl3" Category="Color"
PromptText="Please select a color" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"
ParentControlID="ddl2">
</cc1:CascadingDropDown>
<asp:Button ID="btnClick" runat="server" Text="I want this car." Width="282px" OnClick="btnClick_Click" /><br />
<br />
<asp:Label ID="lblInformation" runat="server" Text="[ No sellection made yet. ]"
Width="279px"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel> </div>
</form>
</body>
</html>

Code Behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace CascadingDropDownDemo
{
public partial class _Default : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnClick_Click(object sender, EventArgs e)
{
// Get selected values
string make = ddl1.SelectedItem.Text;
string model = ddl2.SelectedItem.Text;
string color = ddl3.SelectedItem.Text;

// Output result string based on which values are specified
if (string.IsNullOrEmpty(make))
{
lblInformation.Text = "Please select a make.";
}
else if (string.IsNullOrEmpty(model))
{
lblInformation.Text = "Please select a model.";
}
else if (string.IsNullOrEmpty(color))
{
lblInformation.Text = "Please select a color.";
}
else
{
lblInformation.Text = string.Format("You have chosen a {0} {1} {2}. Nice car!", color, make, model);
}
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string Category)
{
CarsService cs = new CarsService();
return cs.GetDropDownContents(knownCategoryValues, Category);
}

protected void ddl3_SelectedIndexChanged(object sender, EventArgs e)
{
string make = ddl1.SelectedItem.Text;
string model = ddl2.SelectedItem.Text;
string color = ddl3.SelectedItem.Text;

// Output result string based on which values are specified
if (string.IsNullOrEmpty(make))
{
lblInformation.Text = "Please select a make.";
}
else if (string.IsNullOrEmpty(model))
{
lblInformation.Text = "Please select a model.";
}
else if (string.IsNullOrEmpty(color))
{
lblInformation.Text = "Please select a color.";
}
else
{
lblInformation.Text = string.Format("You have chosen a {0} {1} {2}. Nice car!", color, make, model);
}
}
}
}

web services code

using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

using AjaxControlToolkit.Design;
namespace CascadingDropDownDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CarsService : System.Web.Services.WebService
{
// Member variables
private static XmlDocument _document;
private static object _lock = new object();


// we make these public statics just so we can call them from externally for the
// page method call
//
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/CarsService.xml"));
}
}
return _document;
}
}

public static string[] Hierarchy
{
get
{

return new string[] { "make", "model" };
}
}

/// <summary>
/// Constructor to initialize members
/// </summary>
public CarsService()
{
}


/// <summary>
/// Helper web service method
/// </summary>
/// <param name="knownCategoryValues">private storage format string</param>
/// <param name="category">category of DropDownList to populate</param>
/// <returns>list of content items</returns>
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}

}

Good luck


Hi MIB426,

Thanks heaps for your code...I am pretty new to both .NET & AJAX so I need to be a pain and ask a couple more questions.

Where can I get the web.config file from?

This part of your code (web services code) where am I meant to add this to?

Thanks heaps for your help!

using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

using AjaxControlToolkit.Design;
namespace CascadingDropDownDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class CarsService : System.Web.Services.WebService
{
// Member variables
private static XmlDocument _document;
private static object _lock = new object();


// we make these public statics just so we can call them from externally for the
// page method call
//
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/CarsService.xml"));
}
}
return _document;
}
}

public static string[] Hierarchy
{
get
{

return new string[] { "make", "model" };
}
}

/// <summary>
/// Constructor to initialize members
/// </summary>
public CarsService()
{
}


/// <summary>
/// Helper web service method
/// </summary>
/// <param name="knownCategoryValues">private storage format string</param>
/// <param name="category">category of DropDownList to populate</param>
/// <returns>list of content items</returns>
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}

}


Sorry its me again.

Ok I have created a new page called default2.aspx and added the above code. I created a new web service "WebService" and added the above code into WebService.cs.

When I try run the the form I get an error saying "Error 29 Could not create type 'WebService'. C:\Users\shane\Desktop\AJAXEnabledWebSite4\WebService.asmx 1"

What else do I need to change.....Please help!!!!!!!

Thank you

Error1Could not load file or assembly Microsoft.Web.Preview or one of its dependencies. Th

Trying to run the samples and this is the error I get. After looking around I see others have gotten this error but with the beta versions.

My install is not a beta release and I have not had any of the betas installed.

Any ideas?

I would look to your web config file or possibly your machine config file. Im betting you somehow got some old beta settings in it. possibly do a search for Microsoft.Web.Preview in your entire solution.

AjaxButter


The other thing i just noticed is you said you were running the samples. Im betting your using an old compilation of the sample files that was meant to use the beta version redownload the sample your using and give it another go.

Sorry for the double post

AjaxButter


Hi,

If you have installed the AJAX Extensions 1.0, the assembly Microsoft.Web.Preview not exists.

You must to replace all the references and assemblies in the samples for run this.

Hope this helps


Replace with what?

How the Microsoft.Web.Preview not exists with the AJAX extension 1.0, you must to work with the System.Web.Extensions assembly and System.Web.Extensions.Design assembly, installed in the Microsoft ASP.NET folder in Program Files folder.

Replace the web.config with the web.config that is generated in a new ASP.NET AJAX Enabled Web Site.

Or replace your web.config with the web.config file that is in the Microsoft ASP.NET folder.



From InstallationInstructions.txt:

Completing the Installation
--------
After downloading and uncompressing the sample files, copy Microsoft.Web.Preview.dll from the
ASP.NET AJAX CTP installation directory (%Program Files%\Microsoft ASP.NET\ASP.NET 2.0 AJAX
Futures January CTP\v1.0.61025\) to the Bin directory of each sample application. For example,
copy Microsoft.Web.Preview.dll to <installation path>\Contacts\Bin, where <installation path>
is the file path where the ASP.NET AJAX Samples were installed.

You must also copy AjaxControlToolkit.dll from the AJAX Control Toolkit directory to the Bin
directory of each sample application. For example, copy <toolkit installation path>
\AjaxControlToolkit\SampleWebSite\Bin\AjaxControlToolkit.dll to <installation path>\Contacts\Bin,
where <toolkit installation path> is the installation path for the AJAX Control Toolkit and
<installation path> is the file path where the ASP.NET AJAX Samples were installed.

Earlier in InstallationInstructions.txt are the download locations for the Futures CTP and the Control Toolkit.