Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Wednesday, March 28, 2012

postbacks and ajax

I have created dynamic datagrid with vb.net using (no javascript) that has checkboxes and dropdowns, and when checkboxes checks it postsbacks, and shows data comes from database, now I want no postbacks to happen. I guess I can do that in ajax, but need a help on it, since I have never done that before and don't know ajax. Can anybody help me on that?

Hi There,

If you are using .net 2.0 with ajax.net

Try following, this is do a callback when you click on your checkboxes

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

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

<ContentTemplate>

YOUR DATAGRID HERE

</ContentTemplate>

</asp:UpdatePanel>


I am using 1.0 and didn't work on that, I need 2.0 then? Do I need to start with ajax enable website or can I add it those lines later to existing project ?


actually my asp.net version 2.0, but ajax 1.0


Check out all the vid's on ASP.NET AJAX:

http://www.asp.net/learn/videos/default.aspx?tabid=63

This one in particular should help:

http://www.asp.net/learn/videos/view.aspx?tabid=63&id=75

This one discusses what is needed to use ASP.NET AJAX with an existing application:

http://www.asp.net/learn/videos/view.aspx?tabid=63&id=81


Unfortunately I cannot view videos, it says respond denied.


What d4dennis@.inspir3 said should work but you have to add somestuff to your web.config file before the site is "ASP.NET AJAXenabled".


This goes under the <configuration> tag

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

 This goes inside the <pages> tag:
  <controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>

If you haven't made any changes to your <compilation> section replace it with this: (Otherwise change it accordingly)
  
<compilation debug="false">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation
<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>


  Finally add this just above the </configuration> tag:
 
 <system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>
<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>

Hope this helps!


Thank you for laying out this for me, I just found the same thing right before you have sent me and implemented, so web.config is fine now, but in my existing project , I have lots of panels, tables etc. and I tried to put my datagrid inside the this format

<body> <formid="form1"runat="server"> <asp:ScriptManagerID="ScriptManager1"runat="server"/> <asp:UpdatePanelID="UpdatePanel1"runat="server"> <ContentTemplate> <div>

datagrid

</div> </ContentTemplate> </asp:UpdatePanel> </form></body>

which I don't want it to refresh whole page is working but it is something weird happening inside the my grid, I have checkbox and dropdown and textboxes right, when I checked the checkbox, page is not refreshing which is Good, what I want, but because I need to enable dropdown when checkbox checked, refresh happening inside the grid to dropdown, I wonder if I put my updatepanel and contenttemplate to right place or not?


I need when checkbox checked inside the grid, my dropdown inside the grid should enables, gets filled with data without refreshing the page or datagrid. Right now, it is not refreshing the page but inside the grid almost like part of the grid where dropdown there gets refresh( looks like flashing at that area where dropdown sits) I don't want that.

I wrote a lot of working code (at SERVER SIDE) didn't use javascript that does things inside the datagrid when user checks checkboxes. But it was keep refreshing the page with each checkbox clicks that's why I need to use ajax.

Monday, March 26, 2012

Problem about area of focus

Hello frnds,

I have created Web application using AJAX control tool kit......you may view it here......

www.calstate.edu/majors


My problem here is that If I select 1 item from DropDownList(DDL) 1 and then choose DDL2 and then press search button; everything works fine.....

But now If I select other item from DDL1 again, so I want the DDL2 to be set to default value as Before ie. I want it to be to Select Major Type/Degree....so what shud be added in order to change the default value of DDL2 back to original.


Thanks ur help is highly appreciated

Hemil.

write a event for DDL1's selectedindexchanged and set the ddl2's selectedindex to 0.

And also mark enableautopostback to true for ddl1


hi,

After seen the site I think the problem is that the selected value of second DDL is remain as it is so after the search result of in the selected index chnage event of first DDL just make the SelectedValue to default means index to 0 every time then it will be work


I tried changing the same, but When I write the line in the function

protected void majorDDL_SelectedIndexChanged(object sender, EventArgs e)

it says cannot assign to majorDDL_SelectedIndexChanged becoz it is a method grp.......so where shud I write the value 0....


Could you please share your code?


C-sharp file

protected void majorDDL_SelectedIndexChanged(object sender, EventArgs e)
{
visibleOff();
searchButton.Enabled = false;

}

.aspx file

<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /
<label for="majorDDL" style="display:none;">Select Programs Name and Type:</label><asp:DropDownList ID="majorDDL" runat="server"
OnSelectedIndexChanged="majorDDL_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
ServiceMethod="GetDropDownContents"
UseContextKey="True"
Category="major"
LoadingText="..."
PromptText="Degree Major/ Program Name"
ServicePath="MajorsDatabase.asmx"
TargetControlID="majorDDL">
</ajaxToolkit:CascadingDropDown>
<br /><br />
<label for="typeDDL" style="display:none;">Select Programs Name and Type:</label>
<asp:DropDownList ID="typeDDL" runat="server"
OnSelectedIndexChanged="typeDDL_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server"
ParentControlID="majorDDL"
Category="type"
ContextKey="..."
PromptText="Degree Major/ Program Type"
ServiceMethod="GetDropDownContents"
ServicePath="MajorsDatabase.asmx"
TargetControlID="typeDDL">
</ajaxToolkit:CascadingDropDown


I want to make DROPDOWN 2 value to default ie it shud display the value of PromptText="Degree Major/ Program Type".......


I suppose this is automatically handle by extender

http://asp.net/ajax/ajaxcontroltoolkit/samples/

Saturday, March 24, 2012

Problem adding atlas controls to existing web form

I created an atlas web site from the Atlas Template and added some files from another web site, so I tried to add <atlas:ScriptManager...> tag, but VS2005 didn't recognize Atlas (now ASP.Net AJAX) tags.

How can I add Atlas to existing ASP.Net web sites?

i'll need to register the "altas" tag in your web.config file.

I've discovered the problem. Atlas intellisense doesn't work in projects on network shares, so I installed Visual Source Safe and now it recognizes as being run locally.

Problem adding Atlas to an existing site

I have created a test atlas site and successfully used the update panel with some dropdown lists. Now I want to incorporate Atlas into an existing web site. I created a test page in the existing web site and recreated my test page in the existing site. The Atlas components to not seem to work... instead of an ajax update it is doing a full postback.

Here are the things I've checked:

- Atlas dll is included in bin
- Web.config file is updated and matches the test site config exactly
- Test web page is exactly the same as on the test site
- The .asbx extension is registered correctly
- The web site is configured for .Net 2.0

I'm not even sure how to figure out what else is going on here. Any other suggestions or things I can look at here? Thanks!

hello.

have you created a simple page on that site? if so, post it here so that we can see if there's anything wrong with it or if it's a configuration problem...


I have done a simple page on the test site (which works) and the exact same page in the existing site (which doesn't work) so I'm not sure the code provides any value. But here is another clue. When I add the trigger to the update panel through the designer, switch to code view, and then back to designer I get an "error creating control"

It says: Triggers could not be initialized. Triggers could not be added to the collection. Details: Object does not match target type.

Here is the web page code:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="IssueTest.aspx.cs" Inherits="ProjectTrack_IssueTest" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" 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 id="Head1" runat="server"> <title>Untitled Page</title> </head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </atlas:ScriptManager> <asp:DropDownList ID="ClientsDDL" runat="server" DataSourceID="RDI_DB" DataTextField="CO_NAME" DataValueField="Client_ID" OnSelectedIndexChanged="ClientsDDL_SelectedIndexChanged" AutoPostBack=true> </asp:DropDownList><atlas:UpdatePanel runat="server" ID="UpdatePanel1" Mode="Conditional"> <Triggers> <atlas:ControlEventTrigger ControlID="ClientsDDL" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <asp:DropDownList ID="ProjectsDDL" runat="server" DataTextField="PROJ_NAME" DataValueField="PROJECT_NO" AppendDataBoundItems=true AutoPostBack="True" OnSelectedIndexChanged="ProjectsDDL_SelectedIndexChanged"><asp:ListItem>Select a client</asp:ListItem> </asp:DropDownList> </ContentTemplate> </atlas:UpdatePanel> <asp:DropDownList ID="PhaseDDL" runat="server" DataTextField="DESCRIPTION" DataValueField="PHASE" AppendDataBoundItems=true AutoPostBack="True"><asp:ListItem>Select a project</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="TaskDDL" runat="server" DataTextField="TASK" DataValueField="TASK" AppendDataBoundItems=true><asp:ListItem>Select a phase</asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="RDI_DB" runat="server" ConnectionString="<%$ ConnectionStrings:RDI_DevelopmentConnectionString%>" SelectCommand="SELECT [Client_ID], [CO_NAME] FROM [CLIENTS]"></asp:SqlDataSource> <asp:SqlDataSource ID="ProjectListDB" runat="server" ConnectionString="<%$ ConnectionStrings:RDI_DevelopmentConnectionString%>" SelectCommand="SELECT [PROJECT_NO], [PROJ_NAME] FROM [PROJ_NO] WHERE ([CLIENT_ID] = @.CLIENT_ID)"> <SelectParameters> <asp:ControlParameter ControlID="ClientsDDL" Name="CLIENT_ID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="PhaseListDB" runat="server" ConnectionString="<%$ ConnectionStrings:RDI_DevelopmentConnectionString%>" SelectCommand="SELECT [PHASE], [DESCRIPTION] FROM [PHASE] WHERE (([CLIENT_ID] = @.CLIENT_ID) AND ([PROJECT_NO] = @.PROJECT_NO)) ORDER BY [DESCRIPTION]"> <SelectParameters> <asp:ControlParameter ControlID="ClientsDDL" Name="CLIENT_ID" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="ProjectsDDL" Name="PROJECT_NO" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="TasksListDB" runat="server" ConnectionString="<%$ ConnectionStrings:RDI_DevelopmentConnectionString%>" SelectCommand="SELECT [TASK], [DESCRIPTION] FROM [TASK] WHERE ([PHASE] = @.PHASE)"> <SelectParameters> <asp:ControlParameter ControlID="PhaseDDL" Name="PHASE" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>   </form></body></html>

hello.

tell me something: can you run the following code with success:

<atlas:scriptmanager runat="server" id="manager" enablepartialrendering="true" />

<atlas:updatepanel runat="server" id="panel">
<contenttemplate>
<asp:button runat="server" Text="Submit" />
<%=DateTime.Now.ToString() %>
</contenttemplate>
</atlas:updatepanel>


Same results... in my existing web site it causes a postback. In my test web site it does an ajax update (no postback). Does that tell you anything? Thanks.

hello again.

one more question:

open the previous page on the browser, right click on it and look at the source code. find the script element that is used to load the js file (you might have several elements that user the webresource.axd on the page; in this case, you'll have to repeat it to all the items you find). copy the address that is in the src attribute of the script element and add it to the url of the page you have in the browser (you'll probably have to delete a portion of the url before adding the value you've copied from the source file).

can you get the file? ie, can you get the js atlas file? if you can't get the file (you should see the tradidional save dialog), then you have a iis configuration problem...

Problem adding ToolkitScriptManager dynamically

Hi All,

Please help me I am stuck and can not go ahead without resolving this issue.

I have created a post(http://forums.asp.net/p/1141711/1838544.aspx) in Asp.net Ajax Extension Discussion forum but I think for this issue this forum is more appropriate.

Our website has no of pages and I do not want to add ToolkitScriptManager in every file and I want to add it in my base page. I am trying to add ToolkitScriptManager dynamically as suggested in threadhttp://forums.asp.net/p/1039254/1777798.aspx in OnPreInit event. But I am getting exception "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)." What could be reason?

Here is code...

protectedoverridevoid OnPreInit(EventArgs e)

{

if (ToolkitScriptManager.GetCurrent(this.Page) ==null)

{

ToolkitScriptManager Manager =newToolkitScriptManager();Manager.EnablePartialRendering =true;foreach (Control cinthis.Controls)

{

if (cis System.Web.UI.HtmlControls.HtmlForm)

c.Controls.AddAt(0, Manager);

}

}

}

Here is exception

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

Line 519: if (c is System.Web.UI.HtmlControls.HtmlForm)Line 520:Line 521: c.Controls.AddAt(0, Manager);Line 522: }Line 523: }

Any idea what could resolve this issue?

Thanks, V

Hi,

As the error message indicates, there are code blocks in your page, so you can't modify Controls collection.

For instance:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server">
public string hello = "hello";
protected override void OnPreInit(EventArgs e)
{
if (AjaxControlToolkit.ToolkitScriptManager.GetCurrent(this.Page) == null)
{
AjaxControlToolkit.ToolkitScriptManager Manager = new AjaxControlToolkit.ToolkitScriptManager();
Manager.EnablePartialRendering = true;
foreach (Control c in this.Controls)
{
if (c is System.Web.UI.HtmlControls.HtmlForm)
{
c.Controls.AddAt(0, Manager);
break;
}

}

}

}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
}
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<input value=<%=hello%> />

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

It can be solved by assigning the input control's text in code behind.

1. Mark it as runat server

2. In page_load, add : idOfTheInputControl.Value = hello;

Hope this helps.

Problem displaying AjaxControlToolkit website

Hi,

i've created an AjaxControlToolkit website (from a template).

to see that all is working well i've added a TextBox and watermark to it.

everything works greate here... at my computer... but...

when i uploaded it to my domain hosting space the toolkit is not functioning. all Ajax extension features are working but the toolkit features aren't!

and the "funny" part is that i don't get any error - client side nor server side...

any ideas?!?!?

i made sure the latest Ajax extension is installed on my host server and a restart to the machine was performed (even though it was not required)

any help will be appreciated...

Thanks!

Is the toolkit dll installed on the server correctly? Where is it located? In the gac or in the web app bin directory?
The dll is only located at my Bin directory. where else should it be?
Do a View | Source on the page coming off the server and compare it against the local version - that may help show what's not hooked up right.

Problem Getting Atlas Wiki to Work

Help!

I've installed the wiki template and created a project. When I run it the first time, the page loads and all is well. However, when I go to click on links to some of the other pages like "Membership in the Wiki", the URL shows "default.aspx?page=membership%20in%20the%20wiki" as expected, however, the homepage is what is displayed. Other curious behavior:

If I attempt to create a user, that user does in fact get written to the database and I am able to grant it roles in the website configuration, however, if I go back to the wiki to log in, it is stuck on "Validating Credentials"Clicking on either "Comments" or "Contents" gives me a stuck "Loading" message.I have verified the following:
I do have ASPNET & Annonymous internet users with write access to the App_data directoryDatabase connection strings work.Does anyone have any suggestions? I'm about to give up.Update: If I create the Wiki using the "local filesystem" option it works fine. If I try to use the copy tool and copy it to my IIS directory (same machine), I get the bad behavior. Sounds like an IIS problem. Is it configuration? Is it buggy IIS? I'm using 5.1 on XP.

I'm new to the "ajax" world, also to the Atlas Wiki and am having the same issue with the linking.

When creating and article and saving, directly afterwards, the article is displayed correctly.

Yet if I navigate to the contents menu, then to that or any other article currently in the wiki, it routes me to this URL: "default.aspx?page=" then the article's name, but it does not display the article. The contents of that page are always the same.

Problem in Ajax i My ASP.Net WebSite

hi

i am working on my website.(when i created website,i don't select Ajax Enabled Template and it is a default asp.net website)

and i want add ajax feature to my website by drag ScriptManager and UpdatePanel from toolbox.but when i run my website,error shown in IE statusBar.

how to solve my problem ?

should i create new website as Ajax enabled template ?

thanks

Hello,

Make sure you install Ajax on your system, and you need to modify your web.config file.

The best way to modify the config file is, create new ajax project, which will built a web.config file for you.

You then compare your old web.config file with the ajax website web.config file. If you haven't added any information to your old web.config file, I would just copy the ajax web.config file to your current (web) project. And if you already added information into your web.config file, then just copy whatever you don't have from the ajax web.config file to yours.

I hope you understand what I'm talking about =)

WS

Problem in Cascading Drop Down

I have created a website using Cascading DropDown in AJAX control tool kit......

I have 3 DropDown lists.....and the list in 2nd one is populated when an Item from 1st DropDown List is selected...Similarly 3rd DropDown is populated depending on 2nd list.....

My problem is that I get all my values in dropdown 3 list but I wanted to show the whole list of items in my result.....means suppose at the end of the selection I have 3 items in DropDown list 3 then all the items in tat list shud be my result......

can u tell me how to extract tat all the items from DropDown list 3 and display it.....

Hi Hemil,

Based on my understanding, there are three DropDownlists in the page. The second DropDownList is bound according the item selected in the first DropDownList. The third DropDownList is bound according the item selected in the second DropDownList. Now you want to know how to get all the items of third DropDownList. In one word, you want to know how to get a DropDownList's items. If I have misunderstood you, please feel free to let me know.

To get all the items of DropDownList, you should use loop to get them.

To better understand your question, could you please confirm the following information:

If you want to get the value of item, the code should like as follows:

string strResult ="";foreach (ListItem itemin DropDownList1.Items) { strResult += item.Value; } 


Ya u got my problem rite but only thing is that I have all the items in Drop Down list 3 which is populated according to the Items selected from Drop Down1 and Drop Down2.....

So after selecting items from DropDown 1 and 2 I get my result in Drop down 3 Which I need to display all at once.....means all items in drop Down list 3.....

So watever code U gave me will work or no and if yes will it work if i change the item in Drop Down 1 or 2 accordingly Dropdown 3 will change so will it append to the Display result.......I have used Cascading Dropdown of AJAX Control tool kit......

<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server"
ServiceMethod="GetDropDownContents"
UseContextKey="True"
Category="major"
LoadingText="[Loading majors...]"
PromptText="Degree Major/ Program Name"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList1">
</ajaxToolkit:CascadingDropDown>

<br /><br />

<asp:DropDownList ID="DropDownList2" runat="server"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server"
ParentControlID="DropDownList1"
Category="type"
ContextKey="[Loading major types...]"
PromptText="Degree Major/ Program Type"
ServiceMethod="GetDropDownContents"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList2">
</ajaxToolkit:CascadingDropDown
<br /><br /
<asp:DropDownList ID="DropDownList3" runat="server"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" Visible="true">
</asp:DropDownList>

<ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server"
ParentControlID="DropDownList2"
Category="campus"
ContextKey="[Loading campus names...]"
PromptText="Campus"
ServiceMethod="GetDropDownContents"
ServicePath="MajorsDatabase.asmx"
TargetControlID="DropDownList3">
</ajaxToolkit:CascadingDropDown>


Hi Hemil,

The code I posted above is only a simple example, which tells you how to loop the DropDownList. You can use different way to display the result according your requirements.

I hope this helps.


Sir,

I tried implementing ur code but I get only the value which is selected item in Drop Down instead of all the values in DropDown List 3......

I will tell you something more on this...I want to display the result after I select Item in Drop Down List 2.......means as soon as I select one item from Drop Down List 2 and then I should press Submit button so It should give me all the values contained in Drop Down list 3 which I will make Invisible to the user.....So in short there is dropDown list behind the scenes which has all the values in DropDown list........I want to display all the Items in dropdown list 3........after I press Submit button......

So the sequence of operations will be.....

1. Select one item from DropDownlist 1

2. As per the selection in dropdown list 1, Drop Downlist 2 will be populated with values so Select item from drop down List 2.

3. Now behind the scenes I have drop down list 3 but I dunt want to show the DropDown....it has all the Items which I need to display to the user...

4. There is one Submit button which I have to press and it should show all the Items from Drop DOwn list 3...which is present behind the scenes...

Thanks,

hemil.



Hi Hemil,

Thanks for your response.

Based on my understanding about your response above, you should bind the DropDownList3 and then loop this DropDownList3 to display Values in the Button event.

The code of Button event should like as follows:

protected void Button1_Click(object sender, EventArgs e) {//Bind DropDownList3 by the item selected in the DropDownList2 DropDownList3.DataSource = YourDataSource; DropDownList3.DataTextField ="DisplayField"; DropDownList3.DataValueField ="ValueField"; DropDownList3.DataBind();string strResult ="";//loop DropDownList3foreach (ListItem itemin DropDownList3.Items) { strResult += item.Value; } }


I hope this helps.


Hi Hemil,

If you have any question, please post them here and don't need to email me directly. We are glad to help you. If you post the question here, other kindly people will help you too. Thanks for your understanding.

Based on your question and the codes you sent to me, you cannot bind the XML file to DropDownList directly. You should read the XML file to a DataSet or XmlDataSource and bind the DropDownList with the data source.

The code should like as follows:

<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml"></asp:XmlDataSource>

</div>
</form>

protected void Button1_Click(object sender, EventArgs e) { XmlDataSource1.XPath ="/MajorsDatabase/major/type";// Use xpath to filter data you want to display. DropDownList3.DataSource = XmlDataSource1; DropDownList3.DataTextField ="name"; DropDownList3.DataValueField ="name"; DropDownList3.DataBind(); }

I hope this helps.


The code is working ... Thanks ...

But I am facing a new problem ... which is ,.... when I select the first and second drop down box .. I get all the names of the campuses ... where as ... it should display me only campus names depending on the DDL1 and DDL2 selection ...

i.e. DDL => DropDownList

When I select from DDL1 - "Acturial Science"

and DDL2 - "b" ... it should give me only ... Campus Name as "San Jose" and "San Diego".

but it is giving all the Campus name from the XML file under the tag "campus" ...

Is there any way we can query the DataBinding or DataSource ...

Thanks.....


Hi Hemil,

You should add XPath to filter the data you want to display.

For example, If you want to get the type names, which are the child node of major node and this major node's name property is "Advertising", the XPath should like as follow:
XmlDataSource1.XPath = "/MajorsDatabase/major[@.name='Advertising']/type";

So you can write the XPath to filter the data. For more information, seeXmlDataSource.XPath Property.


I hope this helps.


Good Afternoon,

Thanks a lot for the guidance... the code works just perfect for the Static values.

I would like to ask you few things like ...

1. can we pass dynamically selected arguments in Xpath ?

2. do we need to write a query for this dynamic invocation ?

I was trying ...

XmlDataSource1.XPath ="/MajorsDatabase/major [DropDownList1.SelectedItem.Text] /type[DropDownList2.SelectedItem.Text]/campus";

But is is not working ...

As we are selecting Major from DDL1 and Type from DDL2 ... I would like to pass those dynamically selected values in XPath ....

I was also trying ...

int one = 1, two = 1;

XmlDataSource1.XPath ="/MajorsDatabase/major[one] /type[two]/campus"; ====> Not working ... where as if we write

XmlDataSource1.XPath ="/MajorsDatabase/major[1] /type[1]/campus"; ====> works ...

Thanks Again ...


Hi Hemil,

Yes, we can pass parameters to XPath dynamically and easy. Since the parameters are variables, we cannot write them in the XPtah string directly. We should use plus to connect the XPath and parameters.

For example:

string strParameter ="Advertising"; XmlDataSource1.XPath ="/MajorsDatabase/major[@.name='"+strParameter+"']/type";


I hope this helps.


Thanks very much for all your help.

Code is working fine.

Wednesday, March 21, 2012

problem in using AJAX

i am using visual web developer 2005 and SQL Express 2005 with VB as the code behind

i have created a web site using ASP.NET Web Site installed template

now i want to add AJAX to my web site .

i have downloaded the AJAX December CTP and installed and it is working fine with newly created website using the ASP.NET AJAX CTP-Enabled WebSite template

is it possible to convert my existing web site to use AJAX or should i do it from the beginning

please help me

You can convert the website to use Ajax from an Atlas CTP. This guide should help.

http://ajax.asp.net/documentation/Migration_Guide_CTP_to_RTM.aspx