Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Wednesday, March 28, 2012

postback problem

Hi,

I have a control in my update panel which gets data from the database. The trigger for the update panel is a button control. its working fine ( i mean partial page update is happening) when i run my application.

But when this page is opened from an other user's browser, the whole page ( with all the other controls outside the update panel ) is being posted back on button click.

Any help is appreciated.

Hi developer_dotnet,

The same page has different behaviour in another users browser. Can you past your code here so we can analyze it. Thanks

Regards,


Hi developer,

developer_dotnet:

its working fine ( i mean partial page update is happening) when i run my application.

.

You mean in your development environment or you have published your website on this spot ?

developer_dotnet:

But when this page is opened from an other user's browser, the whole page ( with all the other controls outside the update panel ) is being posted back on button click.

First, suggest that we should use a debug tool such as Web Development Helper to make sure whether it make a asynchronous post or not.

If not , we should pay our attention to check if Asp.Net Ajax Extension V1.0 has been installed in the machine which host your website. http://ajax.asp.net/docs/InstallingASPNETAJAX.aspx .If Aajx ControlToolkit Controls used in your application, please add "AjaxControlToolkit.dll" to your bin folder.

If yes , please check the web.config settings .http://ajax.asp.net/docs/ConfiguringASPNETAJAX.aspx

If the problem cannot been resolved by doing these, please show your simple source code here.


I had a similar issue of partial postback. I have made it into a seperate <table> and it worked.


Hi all,

If an Ajax-Enabled page doesn't work properly in the browser, we may do some checking on the broswer security and privacy setting.

The following table lists required browser security and privacy settings for both user browsing and site development. In all cases, the recommended settings are the default settings for that browser.

Internet Explorer 6

Make sure that theInternet Zone in the Security Zones settings is set toMedium.

Internet Explorer 7

Make sure that theInternet Zone in the Security Zones settings is set toMedium-High.

FireFox 1.5 or later versions

In theTools menu underOptions, make sure thatEnable JavaScript is selected.

Opera 9.0 or later versions

In theTools menu underQuick preferences, make sure thatEnable JavaScript is selected.

Safari 2.0 or later versions

ClickSafari,Preferences,Security, and then Web Content and make sure thatEnable JavaScript is selected.

Hope it helps.

Postback problem with dynamically added ModalPopupExtender

In my task i have to create ModalPopupExtender dynamically, and add an .ascx control to it. This is the code:

Test.aspx page:

<

asp:ScriptManagerProxyrunat="server"ID="proxy"/>

<

asp:UpdatePanelrunat="server"ID="ajaxPanel"RenderMode="Inline"UpdateMode="Conditional"><ContentTemplate><asp:Panelrunat="server"ID="panel"><asp:Buttonrunat="server"ID="btn2"Text="Show Control"OnClick="btn2_Click"/></asp:Panel>

<%

--<asp:Button runat="server" ID="btn1" Text="test1" OnClick="btn1_Click" />--%>

</ContentTemplate></asp:UpdatePanel>

test.ascx control:

<

asp:ScriptManagerProxyrunat="server"ID="proxy"/>

<

asp:UpdatePanelrunat="server"ID="ajaxPanel2"RenderMode="Inline"UpdateMode="Always"><ContentTemplate> <asp:Buttonrunat="server"ID="btnTest2"Text="test2"OnClick="btnTest2_Click"/></ContentTemplate></asp:UpdatePanel><asp:Buttonrunat="server"UseSubmitBehavior="false"ID="btnTest"Text="Close OK"OnClick="btnTest_Click"/><asp:Buttonrunat="server"UseSubmitBehavior="false"ID="btnTestClose"Text="Close"OnClick="btnTest_Click"/>

In aspx page:

protected

overridevoid OnInit(EventArgs e)

{

base.OnInit(e);Control c = LoadControl("~/test.ascx");

c.ID =

"customModalControl";Panel p =newPanel();

p.Width = 300;

p.Height = 200;

p.CssClass =

"modalPopup";

p.ID =

"modalPanel_";_modalPopup =newModalPopupExtender();

_modalPopup.ID =

"modalPopup";

_modalPopup.DropShadow =

true;

_modalPopup.BackgroundCssClass ="modalBackground";

_modalPopup.PopupControlID = p.ID;

_modalPopup.TargetControlID = btn2.ID;

Control c2 = c.FindControl("btnTest");

_modalPopup.OkControlID = c2.ClientID;

c2 = c.FindControl("btnTestClose");

_modalPopup.CancelControlID = c2.ClientID;

p.Controls.Add(c);

panel.Controls.Add(_modalPopup);

panel.Controls.Add(p);

}

protectedvoid btn1_Click(object sender,EventArgs e)

{

}

protectedvoid btn2_Click(object sender,EventArgs e)

{

_modalPopup.Show();

}

onInit event, i create ModalPopupExtender and a panel for ascx control. All works fine, but is one problemCrying, when i click btnTest2 on ModalPopup, rises postback for the page, but ascx control didn't receive btnTest2 _OnClick event. Maybe someone know where is a problem. Thank you.

Try to change change some of your codes to specify asynchronous post back.
<asp:UpdatePanel runat="server" ID="ajaxPanel2" RenderMode="Inline" UpdateMode="Always">
<ContentTemplate>
??????<asp:Button runat="server" ID="btnTest2" Text="test2" OnClick="btnTest2_Click"/>
</ContentTemplate>
<triggers>
????<asp:AsyncPostBackTrigger ControlID="btnTest2" EventName="Click"/>
</triggers>

</asp:UpdatePanel>
Wish this can help you.

PostBack with query string...

hi,

Here is what I am trying to do, I have a user control, usercontrol is one of many being loaded in a single default.aspx, inside this user control, there are Atlas TabPanels, in several tab panels there are user controls, in these user controls, there are controls causing a postback, the problem is when page is reloaded, it returns to default tabs, I like to pass a query string that contains active tab, but how can I do this in javascript? I am not sure where to put this here or in Atlas forum. Thanks in advanced.

Hi,

I think u need to set the smartnavigation propery to true . so that focus will not be lost during the postback

Swati


Hi,

Because there is a full postback, you need to use a HiddenField to maintain the current active tab index.
After the postback completes, active the corresponding index with javascript.
Like this:
$find('<%=TabContainer1.ClientID%>').set_activeTabIndex(the value kept in the hiddenfield);

Hope this helps.

Posting from Tab Control does not work

Hi all,

I am new to AJAXtoolkit and I tried the following code it runs fine but does not input values in textbox nor updates the image

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script type="text/javascript">
function PanelClick(sender, e) {
}

function ActiveTabChanged(sender, e) {
__doPostBack('<%= Tabs.ClientID %>', sender.get_activeTab().get_headerText());
}
</script>
<div>
<ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="150px"
OnClientActiveTabChanged="ActiveTabChanged"
OnActiveTabChanged="ActiveTabChangedServer">
<ajaxToolkit:TabPanel runat="Server" ID="Panel1" HeaderText="Tab One">
<ContentTemplate>
PAGE ONE - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel runat="Server" ID="Panel2" HeaderText="Tab Two" >
<ContentTemplate>
PAGE TWO - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>

<ajaxToolkit:TabPanel runat="Server" ID="Panel3" OnClientClick="PanelClick" HeaderText="Tab Three">
<ContentTemplate>
PAGE THREE - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer> <br />
<asp:Image ID="Image1" runat="server" />
<asp:TextBox ID="txtTabSelect" runat="server" />
</div>
</form>

in the code behind I have this:

protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Tabs);
}

protected void ActiveTabChangedServer(object sender, EventArgs e)
{
if (Tabs.ActiveTab == Panel1)
{
Image1.ImageUrl = "~/Images/HomeEnabled.jpg";
txtTabSelect.Text = "Selected Panel 1";

}

if (Tabs.ActiveTab == Panel2)
{
Image1.ImageUrl = "~/Images/ProductsEnabled.jpg";
txtTabSelect.Text = "Selected Panel 2";
}

if (Tabs.ActiveTab == Panel3)
{
Image1.ImageUrl = "~/Images/SupportEnabled.jpg";
txtTabSelect.Text = "Selected Panel 3";
}

}

Please do tell me what am I doing wrong. I tried debugging, the watch shows that the values are present but do display.
Thanks,

do you have the autopostback property on the tabs container set to true?


Hi,

ajaxToolkit:TabContainer does not have the property and I did try adding AutoPostBack="true", compiled it and ran but it still does not work. what baffles me is it calls the

protected void ActiveTabChangedServer(object sender, EventArgs e)
{
.....

}

on the server and I can see the values in the watch window but when the page reloads, the values are not there

I have this in the page load event

if (!Page.IsPostBack)
{
ScriptManager1.RegisterAsyncPostBackControl(Tabs);
}

Thanks,


Hi,

It's caused by not calling __dopostback method in a correct way. I suggest using a hidden button to trigger postback. Here is a sample:

<%@. 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">protected void Page_Load(object sender, EventArgs e) { //ScriptManager1.RegisterAsyncPostBackControl(Tabs); } protected void ActiveTabChangedServer(object sender, EventArgs e) { if (Tabs.ActiveTab == Panel1) { Image1.ImageUrl = "~/Images/HomeEnabled.jpg"; txtTabSelect.Text = "Selected Panel 1"; } if (Tabs.ActiveTab == Panel2) { Image1.ImageUrl = "~/Images/ProductsEnabled.jpg"; txtTabSelect.Text = "Selected Panel 2"; } if (Tabs.ActiveTab == Panel3) { Image1.ImageUrl = "~/Images/SupportEnabled.jpg"; txtTabSelect.Text = "Selected Panel 3"; } //Response.Write(DateTime.Now.ToString()); } </script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <script type="text/javascript"> function PanelClick(sender, e) { } function ActiveTabChanged(sender, e) { $get("<%= Button1.ClientID%>").click();// __doPostBack('<%= Tabs.ClientID%>', sender.get_activeTab().get_headerText()); } </script> <div><asp:Button runat="server" style="display:none;" Text="Button" ID="Button1"></asp:Button> <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="150px" OnClientActiveTabChanged="ActiveTabChanged" OnActiveTabChanged="ActiveTabChangedServer"> <ajaxToolkit:TabPanel runat="Server" ID="Panel1" HeaderText="Tab One"> <ContentTemplate> PAGE ONE - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel runat="Server" ID="Panel2" HeaderText="Tab Two" > <ContentTemplate> PAGE TWO - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel runat="Server" ID="Panel3" OnClientClick="PanelClick" HeaderText="Tab Three"> <ContentTemplate> PAGE THREE - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> </ajaxToolkit:TabContainer> <br /> <asp:Image ID="Image1" runat="server" /> <asp:TextBox ID="txtTabSelect" runat="server" /> </div> </form></body></html>

Hi Raymond Wen,

I tried your approach too.. but the error occurs again.

It gives me "Microsoft JScript runtime error: 'this.get_element().style' is null or not an object". I dont know what it is and why does it occur as I have not written this piece of code.

upon using a debugger it shows as this "this.get_element().style.visibility = 'visible';" which is present in the

_app_onload funtion like this:

_app_onload : function(sender, e)
{

.... this.get_element().style.visibility = 'visible';

}

Thanks for you help,
Stephen


Can you create a simple page to reproduce it?

Posting On Ajax Help Required.

Hi All,

My requirement is like displaying random advertisements in masterpage. I had a page with Ajax Timer control which on Timer_Tick event fetches me a new image and bind to <asp:hyperlink>, my problem is on page_load also i want to display image, but image is displayed only on Timer_Tick after some fixed 3000 seconds is elapsed. On page_load i want to display same images, my images are dynamic comes from database, i store them in a dataset, and binds to asp:hyperlink on timer_tick. Can anyone help, on how to display image on page_load, is there any way how i can attach the server side event (Timer_Tick) on page_load also, so that it will fetch me the image.

Thanks In Advance,

Karthikeyan.

Consider using the AdRotator control.

The AdRotator control selects and displays an ad randomly each time a page is refreshed.

The AdRotator control in ASP.NET 2.0 populates its image and navigation properties in 3 different ways -
Database, XML and also programmatically.

Check these links for more info & code samples -
http://www.ipona.com/samples/0321257278/11/AdRotator-Bound.aspx
http://www.ipona.com/samples/0321257278/SourceViewer/SrcView.aspx?file=/samples/0321257278/11/AdRotator-Bound.aspx
http://www.c-sharpcorner.com/UploadFile/mahesh/adrotator06142007110621AM/adrotator.aspx
http://blogs.msdn.com/acoat/archive/2005/11/07/AdRotator-Dynamic-Image-Generation.aspx


Thanks for your valuable suggestion, but my requirement is i don't want to do a postback for whole page, just for banner, what i want is to do a Asynchronous postback on fixed timer interval and change banner. First time when the page load there is no banner getting displayed. This is my problem, is there any way through which i can again call Timer_Tick event in page_load so that for the first time a image will be loaded.

Thanks & Regards,

karthikeyan.

PRB: Master Pages and Update Panels/Script Manager - AJAX Magic not working

I have a master page that has the script manager control and a content place holder

I have a content page that is using the above master page and with a gridview control wrapped in an update panel

When the content page doesn't use master pages and the script manager is placed within the content page along with the panel, everything works fine

The problem arises when the master page has the script manager and thhe content page just has the update panel with the gid view. It seems to be doing a regular postback and the ajax plumbing doesn't seemto have any effect..

I also tried adding a page initi handler and specifying the trigger in the code behind but with no luck..

generated page source with script manager in master page is listed below. Why does gettting a common master page scnario be so difficult to getv it working..Please point me in the right direction

<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('_ctl0:ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['t_ctl0:ContentPlaceHolder1:panel1'], [], [], 90);

//]]>
</script>


Genertated source when the script managersits on the page and the content page does not use any master pages

<script <script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tpanel1'], [], [], 90);

//]]>
</script>

Hi Ajaxnewbie,

Could you please post your code, so we can see how you have implemented it. Thanks

Regards,


Good question... I have exactly the same problem. I wish there would be a valid answer for this post.

thanks!

Pre Fetching Data - InitialData Control?

Are there any features in ASP.NET AJAX for pre-fetching data? I'm thinking of a feature that would prevent the app from frequently pinging the web server for data (i.e. auto complete, cascading drop down).

From what I can tell, at one point there was an "InitialData" control that was aimed at sending a chunk of data down with the first request. It seems however that this control has been pulled from both Beta2 and the Futures. Does anyone know the status of this control?

Thanks!

Here is a solution for pre-fetching data for your reference.
????At any point in an Ajaxian application's lifetime, the user has the option to perform a number of activities. At the very least, there are always two things the user could do in the next moment: (a) close the application (by quitting the browser or closing the application window/tab); (b) nothing. And of course, there are usually a multitude of application-specific activities that can occur at any time.

Some of these user activities will trigger a remote scripting call to the server before returning for browser-side processing, and the delay will usually be noticeable. That's unfortunate for usability, because responses should ideally feel as if they are instantaneous. The computer not being able to freeze time, the response will never really be instantaneous. But from a usability perspective, it should ideally give that impression. To provide results at a pace that is below the level of human consciousness, a typical guideline is that the application should respond in under 10 milliseconds. That's a hard ask when a trip to the server is required. Especially in a global context, where a trip to the sever and back might cost a second or more due to network overheads.

The obvious motivation for instantaneous feedback is throughput: the user can achieve more because they're not waiting as long for results. Actually, that's not such a major issue: what's a few seconds when you're working on a document for half-an-hour?

Often, the biggest downside of latency is the distraction it causes. The user is focused on a task, and may well be in a state of "flow". A delay will cause a loss of concentration and, in addition to the time it takes to get back to this train of mind, there's also a risk that an idea might be lost forever.

Another problem is simply user frustration. Users generally like to feel in control of a system, so it's not ideal when the system causes delays, especially unpredictable delays.

A final issue with latency is its effect on responsivenes. When users are making decisions in real-time, they need real-time data. For an application such as financial trading, even a consistent 100-millisecond lead can make a big impact on overall performance.

Pre-fetching attempts to remove the delay altogether for certain user actions. It's usually infeasible to pre-fetch results for all actions, so the designer must be judicious in anticipating actions. We are especially interested in actions which are likely to be performed, so that the probability of no response is high. Furthermore, even unlikely actions may also be worth pre-fetching for, if they are critical to the application. Imagine an emergency response system, where the choices are "View your preferences", "Work on reports", and "Dispatch emergency units". The last of these might not occur very often, but which one would you like to be prefetched?

Another downside of pre-fetching is erratic behaviour. A good usability principle is consistent behaviour, but with Predictive Fetch, the user may be surpised that some commands respond instantaneously, while virtually identical commands take a long time. To make the waiting time more comfortable, consider showing a Progress Inidicator.
Advanced Networking Scenarios Not Available in the RTM Release
The following networking features of the CTP release willnot be available in the RTM release:
?The iframe executor. This feature provided support for cross-domain calls, and is not available in RTM release in part because of security concerns.
?The following infrequently used features:
oAssembly-based method calls.
oInitialData control.
oBatching of Web service calls.

Prefetching Images

I am using the update panel, and the timer control to automatically change a person's profile text, and their photo (small 65x65 pixels). Everything works well so far, except the transition is not always smooth for the photo.

Before the images/photos become cached in the browser, the default broken (link-to-image) image shows up, before the relevant photo loads. After that image loads the first time, the transition is smooth.

Is there a way to prefetch these images (approximately 8) when the page loads?

Thanks,

Karls

The easiest way I know of is to create a .js function to preload the images. Something like:

function preload(){
var imageUrls = ["img1.jpg","img2.jpg","img3.jpg"];
var images = [];
for(var i=0;i<imageUrls.length;i++){
var image = new Image();
image.src = imageUrls[i];
images.push(image);
}
}

That you'd call that function during pageLoad(). Setting the 'src' of the image object should cause the browser to start downloading that image.


Nice,

I would like to try that, but I am having a problem converting this to VB. Can anyone convert this?Huh?


No, i'ts javascript.


Ahh, makes sense now.

Thanks.

Monday, March 26, 2012

pre-populating a modalpopupextender

Hi All,

I am using a modalpopupextender control on a form. The popup is actually a panel as opposed to another seperate from. To date the method for working like this has worked fine, however I have never had areason to pre-populate the popup. This time I do and now I have a problem.

My main form displays items based on a user selection. At the bottom of the page they are allowed to add or remove items so for this we want to pre-populate the popup before displaying it. To keep things simple for the moment I've just placed a label on my panel that is part of the popup. when the user has made a selection on the main page, I set the label ready for when the user may decide to use the popup. The probem is that when the popup is displayed, the label hasn't got the value. To help understand what I'm doing here's some of my code.

<cc1:ModalPopupExtender ID="mpeModifyRelationships" runat="server" PopupControlID="ModifyRelationships" TargetControlID="btnFake" BackgroundCssClass="modalBackground" CancelControlID="RelationshipCancelButton" ></cc1:ModalPopupExtender><script type="text/javascript">function showRelationShipPopup(){$get('<%=ModifyRelationships.ClientID%>').className = "modalpopup";$find('<%=mpeModifyRelationships.ClientID%>').show();return false;}</script>

then also on the main page I have this button. This makes the call to the above function causing the popup to display.

<asp:Button ID="btnModify" runat="server" Text="Modify Relationship" Enabled="false" OnClientClick="return showRelationShipPopup()" />
Now my popup is made up thus:
 
 <asp:Panel ID="ModifyRelationships" runat="server" Height="500px" Width="1000px" BackColor="White" BorderStyle="Solid" CssClass="hidden" ScrollBars="Auto"> <table> <tr> <td>Attribute: <asp:Label ID="lblAttribute" runat="server" Text=""></asp:Label></td> <td>Component: <asp:Label ID="lblComponent" runat="server" Text=""></asp:Label></td> <td>Sub-Component: <asp:Label ID="lblSubComponent" runat="server" Text=""></asp:Label></td> </tr> </table> Associated Sors <div style="margin-left: 20px; margin-right: 20px" class="box"> <asp:ListBox ID="lstBoxAssSors" SelectionMode="single" runat="server" Height="120px" Width="936px"></asp:ListBox> </div> <asp:Button ID="RelationshipCancelButton" runat="server" Text="Cancel" CausesValidation="False" Width="80px" /> </asp:Panel>
So behind the scenes I'm setting lblAttribute.text, but when the button is pressed the popup displays, but the text is empty.

See this thread:http://forums.asp.net/p/1149333/1870370.aspx

-Damien

Preselecting a value in the CascadingDropDown control

G'day,

I have a form that saves and loads data from a database. Creating new forms is fine however when reloading hthe form for editing I want the CascadingDropDown control to have its previously selected value displayed.

I have tried the obvious such as loading the controls data and using SelectedValue = someId but it didn't work (probably not surprising!). I also tried setting the controls Text property incase Atlas detected a non empty value and left it alone. I had a bit of a look at the source but I don't yet know enough about the architecture to answer the question myself or to write some code.

Is there a way in this version of preselecting a value when setting up a form from server data on an initial page load?

Keep up the good work guys!

Regards,
Steven.

If you put the following code into the Page_Load for the CascadingDropDown.aspx, it will initialized the first item:

CascadingDropDown1.TargetProperties[0].ClientState ="BMW (value)";

Unfortunately you can't do this for other ones because the change of the first item to the specified value will clear the subsequent items, so we'll need to make improvements here.

But in general the idea is that you should be able to set the ClientState to be the string version of thevalue you want to set (not the text label).

Thinking more about this I think there's a few things we'll do in a future release (might not make our next refresh):

1) Add a strongly typed property for this e.g. "Selected" value

2) Try to make it so the value doesn't flash before the text gets set

3) Make sure you can do more than just the top level here.

Thanks for pointing this out, it's good feedback.

Thanks,

Shawn


So, am I to understand that currently values cannot be selected in dependent lists based on data that that was retrieved from a database?

When I user selects an item to edit, I populate the form with all the existing data for that item, however, some of my dependent lists are not getting the SelectedValue set.

I have an Account list (the parent), I am able to set its SelectedValue.

Sub-Account, Contact, Network and Gateway are dependent on Account. Gateway Version is dependent on Gateway.

When I populate my form the SelectedValue is set successfully for the following lists:

Account, Gateway, Gateway Version

The other lists are disabled and show the PromptText. This would be less confusing to me if ALL dependent lists were disabled with the prompt text selected.

Is there a way to make this work? Or do I need to abandon the CascadingDropDown and find another solution?

(My original post:http://forums.asp.net/thread/1383830.aspx)


It sounds like you have a 1:many parent:child relationship going on here. If so, then I think I fixed the problem withwork item 1704. Please trya recent development release and let us know if it's still not working.

(My app is a ticketing system)

I downloaded the Wed, 30 Aug 2006 17:53:43 GMT version and it solved my issue with the values of the "child" lists not getting selected when viewing/editing an existing ticket. However, now when I go to add a new ticket, my page hangs when it loads the CascadingDropDowns. My cursor becomes an hour glass and my browser becomes unresponsive. My lists never get populated, not even the "parent".

Eventually I get this error: "A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

I'll download a different development release while I wait for a response and see if that makes a difference.

(Side note: I was going to upload a screen shot of the error, but I don't have permission to perform uploads.)


It sounds like either you have a circular reference in your page - or CascadingDropDown is adding one. :) If nothing stands out for you, please post a simple sample so we can have a look. Thanks!

If I add the CascadingDropDownProperties like this (below) the "Add New Ticket" pages hangs on load. However, the "Edit Existing Ticket" page will load/populate just fine - including all of the "child" lists.

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="AccountList"

Category="Account"

PromptText="-- Select Account --"

ServiceMethod="GetAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ExchangeList"

PromptText="-- Select Exchange --"

Category="Exchange"

ServiceMethod="GetExchangeList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ContactList"

ParentControlID="AccountList"

PromptText="-- Select Contact --"

Category="Contact"

ServiceMethod="GetContactList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="SubAccountList"

ParentControlID="AccountList"

PromptText="-- Select Sub-Account --"

Category="SubAccount"

ServiceMethod="GetSubAccountList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="NetworkList"

ParentControlID="AccountList"

PromptText="-- Select Network --"

Category="Network"

ServiceMethod="GetNetworkList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayList"

ParentControlID="AccountList"

PromptText="-- Select Gateway --"

Category="Gateway"

ServiceMethod="GetGatewayList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayVersionList"

ParentControlID="GatewayList"

PromptText="-- Select Gateway Version --"

Category="GatewayVersion"

ServiceMethod="GetGatewayVersionList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

____________________________________________________________________________________________________

If I add the CascadingDropDownProperties like this (below) the "Add New Ticket" page loads just fine, however, the "Edit Existing Ticket" page doesn't populate the "child" lists properly - only Account, Gateway, and GatewayVersion have the correct values selected.

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="AccountList"

Category="Account"

PromptText="-- Select Account --"

ServiceMethod="GetAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ExchangeList"

PromptText="-- Select Exchange --"

Category="Exchange"

ServiceMethod="GetExchangeList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ContactList"

ParentControlID="AccountList"

PromptText="-- Select Contact --"

Category="Contact"

ServiceMethod="GetContactList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="SubAccountList"

ParentControlID="AccountList"

PromptText="-- Select Sub-Account --"

Category="SubAccount"

ServiceMethod="GetSubAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="NetworkList"

ParentControlID="AccountList"

PromptText="-- Select Network --"

Category="Network"

ServiceMethod="GetNetworkList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayList"

ParentControlID="AccountList"

PromptText="-- Select Gateway --"

Category="Gateway"

ServiceMethod="GetGatewayList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayVersionList"

ParentControlID="GatewayList"

PromptText="-- Select Gateway Version --"

Category="GatewayVersion"

ServiceMethod="GetGatewayVersionList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>


We'll probably need the corresponding web service (or one that returns close enough data to reproduce the problem), too, please. If this can be reproduced with the SampleWebSite's web service, a demonstration using that is also fine.

Preselecting item in CascadingDropDown from the values in the database

I have a control that you select the state, city, zip. This is then stored in the database. When I want to edit that record, I want it to select the item from the value in the database. How can I accomplish this.

Example:

ID STATE CITY ZIP
0 PA PERKASIE 18944

Gets inserted into database. When editing ID 0, it needs to preselect PA, PERKASIE, 18944 in the cascading drop downs.

Hi,

You can specify a default item in the method that fills the DDL.

And the problem is how to determine which item should be the default one. I think you can keep the information of it in session, when the user clicks a button to start editing. For example:

void btnEdit_Click()

{

CascadingDropDown2.ContextKey = "the value of the item to be preselected";

}

public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(
string knownCategoryValues, string category, string contextKey)
{
AjaxControlToolkit.CascadingDropDownNameValue[] result = new AjaxControlToolkit.CascadingDropDownNameValue[10];
for (int i = 0; i < 10; i++)
{
result[i] = new AjaxControlToolkit.CascadingDropDownNameValue();
result[i].name = i.ToString() + " " + category + " of " + knownCategoryValues + "name";
result[i].value = i.ToString() + " " + category + " of " + knownCategoryValues + "value";

if(result[i] == contextKey) result[i].isDefaultValue = true;
}
return result;
}


Hope this helps.


Putting this somewhere in the page initialization might work, too:

MyCascadingStateDropDown1.SelectedValue = mystateid;

This seems to invoke the WebMethod to prepopulate the list, preselect the default, and invoke the cascade.



Yes, this help!


I am using the CascadingDropDownList control for two DropDownList I have on my page. The first is a GroupType and the seccond is a Group. I hvae this all working with loading the data from the WebService. All works great except for when I try to go into the Edit Mode. In Edit Mode, I need to set the two DropDwonList with the items the user selected in edit mode.

Here is a section of my code from the C# side of things where I am trying to set the ContextKey...

CascadingDropDownGroupType.ContextKey = dr2["GRPLKUPiGroupType"].ToString();

CascadingDropDownGroup.ContextKey = dr2["GRPLKUPsGroupCode"].ToString();

Here is my WebService Code... (I have included the complete WebService) Keep in mind the WebService works fine, I just need to know where / how to set the items I want to display as SELECTED in the DDL when the user goes into EDIT MODE.

using System;

using System.Web;

using System.Collections;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.SessionState;

using AjaxControlToolkit;

using System.Data;

using System.Data.SqlClient;

using System.Web.Script.Services;

using boyce;

///<summary>

///</summary>

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

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

publicclassBoyceWebService : System.Web.Services.WebService

{

public BoyceWebService()

{

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupTypes(string knownCategoryValues,string category)

{

string[] sArray =newstring[10];

SessionManager CurrentSession;

CurrentSession =SessionManager.GetSessionInfo();

if (CurrentSession !=null)

{

category = CurrentSession.iSelectedGroupTypeId.ToString();

}

else

{

System.Diagnostics.Debug.WriteLine("GetTheGroupTypes -- Session NULL");

}

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();

sArray[0] =string.Empty;

sArray[1] ="-1";

sArray[2] =string.Empty;

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S9", sArray, oSTRUCT);SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

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

if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

string sTheGroupType = (string)drLOOP["GRPTYPsGroupType"];

int iTheGroupTypeId = (int)drLOOP["GRPTYPiID"];

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString()));

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupsForTheGroupType(string knownCategoryValues,string category)

{

StringDictionary kv =CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int iTheGroupTypeId = -1;if (!kv.ContainsKey("GroupType") || !Int32.TryParse(kv["GroupType"],out iTheGroupTypeId))

{

returnnull;

}

string[] sArray =newstring[10];

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();

sArray[0] =Convert.ToString(iTheGroupTypeId);

sArray[1] ="-1";

sArray[2] =string.Empty;

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S10", sArray, oSTRUCT);SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

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

if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

values.Add(newCascadingDropDownNameValue((string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPiID"].ToString()));

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

}


I figured this one out.. All you have to do is in the WebService add / replace the values add with the following

if (Convert.ToInt32(CurrentSession.iSelectedGroupTypeId.ToString()) == iTheGroupTypeId)

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),false));

}


Does anybody know then why setting the isDefaultValue (the third parameter to the constructor of CascadingDropDownNameValue) doesn't do anything? I have debugged my page to confirm that I am indeed setting that value however when the webmethod returns the results it always selects the first value.

Any help would be greatly appreciated.

Thanks,


I did get this to work, and here is the complete WebService I used. Now keep in mind that some of the code will not apply as it references our data access layer we use. However the part you are asking about is there and working. You basically set the "contextKey" inside your normal code and then the web service has to be modified to pass that "contextKey" in. From there, you use the value of the "contextKey" to know if you should set the DefaultValue or not.

In your code, when the page is loaded, you set the value of the context key to what your DEFAULT VALUES are to be. In my example, I have a DDL for GROUP TYPE and a DDL for GROUP.

CascadingDropDownGroupType.ContextKey = dr2["GRPLKUPiGroupType"].ToString();

CascadingDropDownGroup.ContextKey = dr2["GRPLKUPsGroupCode"].ToString();

==================================================================================

Here is the WebService Code.....

==================================================================================

using System;

using System.Web;

using System.Collections;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.SessionState;

using AjaxControlToolkit;

using System.Data;

using System.Data.SqlClient;

using System.Web.Script.Services;

using boyce;

///<summary>

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

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

publicclassBoyceWebService : System.Web.Services.WebService

{

public BoyceWebService()

{

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupTypes(string knownCategoryValues,string category,string contextKey)

{

string[] sArray =newstring[10];

SessionManager CurrentSession;

CurrentSession =SessionManager.GetSessionInfo();

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();

sArray[0] = CurrentSession.sSelectedGroupScreenTYPE;

sArray[1] = contextKey.ToString();

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S9", sArray, oSTRUCT);SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

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

if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

string sTheGroupType = (string)drLOOP["GRPTYPsGroupType"];

int iTheGroupTypeId = (int)drLOOP["GRPTYPiID"];

if (contextKey.ToString().Trim() !=string.Empty || contextKey.ToString().Trim() !="-1")

{

if (Convert.ToInt32(contextKey.ToString()) == iTheGroupTypeId)

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),false));

}

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString()));

}

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupsForTheGroupType(string knownCategoryValues,string category,string contextKey)

{

StringDictionary kv =CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int iTheGroupTypeId = -1;if (!kv.ContainsKey("GroupType") || !Int32.TryParse(kv["GroupType"],out iTheGroupTypeId))

{

returnnull;

}

string[] sArray =newstring[10];

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();sArray[0] =Convert.ToString(iTheGroupTypeId);

sArray[1] = contextKey.ToString();

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S10", sArray, oSTRUCT);

SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

List<CascadingDropDownNameValue> values =newList<CascadingDropDownNameValue>();if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

if (contextKey.ToString().Trim() !=string.Empty || contextKey.ToString().Trim() !="-1")

{

if (drLOOP["GRPLKUPsGroupCode"].ToString() == contextKey.ToString())

{

values.Add(newCascadingDropDownNameValue(

(string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue((string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString(),false));

}

}

else

{

values.Add(newCascadingDropDownNameValue((string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString()));

}

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

}


I have no idea what happened to my last post.. SORRY.. Here is the WebService code...

using System;

using System.Web;

using System.Collections;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.SessionState;

using AjaxControlToolkit;

using System.Data;

using System.Data.SqlClient;

using System.Web.Script.Services;

using boyce;

///<summary>

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

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

publicclassBoyceWebService : System.Web.Services.WebService

{

public BoyceWebService()

{

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupTypes(string knownCategoryValues,string category,string contextKey)

{

string[] sArray =newstring[10];

SessionManager CurrentSession;

CurrentSession =SessionManager.GetSessionInfo();

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();

sArray[0] = CurrentSession.sSelectedGroupScreenTYPE;

sArray[1] = contextKey.ToString();

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S9", sArray, oSTRUCT);SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

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

if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

string sTheGroupType = (string)drLOOP["GRPTYPsGroupType"];

int iTheGroupTypeId = (int)drLOOP["GRPTYPiID"];

if (contextKey.ToString().Trim() !=string.Empty || contextKey.ToString().Trim() !="-1")

{

if (Convert.ToInt32(contextKey.ToString()) == iTheGroupTypeId)

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),false));

}

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString()));

}

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

[WebMethod(true)]publicCascadingDropDownNameValue[] GetTheGroupsForTheGroupType(string knownCategoryValues,string category,string contextKey)

{

StringDictionary kv =CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int iTheGroupTypeId = -1;if (!kv.ContainsKey("GroupType") || !Int32.TryParse(kv["GroupType"],out iTheGroupTypeId))

{

returnnull;

}

string[] sArray =newstring[10];

string DSN = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinancialConnectionString1"].ToString();

DataSet ds =newDataSet();

object oSTRUCT =newobject();

string sSQL =string.Empty;

DataCallManager.InitArray();sArray[0] =Convert.ToString(iTheGroupTypeId);

sArray[1] = contextKey.ToString();

sSQL =DataCall.GetSQL("tblLookupGroupTypes_T","S10", sArray, oSTRUCT);

SqlConnection cn =newSqlConnection(DSN);

cn.Open();

SqlDataAdapter dscmd =newSqlDataAdapter(sSQL, cn);

dscmd.Fill(ds,"DCM_Get");

List<CascadingDropDownNameValue> values =newList<CascadingDropDownNameValue>();if (ds.Tables.Count != 0)

{

foreach (DataRow drLOOPin ds.Tables[0].Rows)

{

if (contextKey.ToString().Trim() !=string.Empty || contextKey.ToString().Trim() !="-1")

{

if (drLOOP["GRPLKUPsGroupCode"].ToString() == contextKey.ToString())

{

values.Add(newCascadingDropDownNameValue(

(string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue((string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString(),false));

}

}

else

{

values.Add(newCascadingDropDownNameValue((string)drLOOP["GRPLKUPsGroupName"], drLOOP["GRPLKUPsGroupCode"].ToString()));

}

}

}

cn.Close();

dscmd.Dispose();

cn.Dispose();

return values.ToArray();

}

}


Hmmm. I am not using a context key but I am still conditionally adding the true parameter to the new cascadingdropdownvalue. Also, from my understanding of its constructor, isDefaultValue defaults to false if a bool is not passed. Below is my code, I am using the selected value from the previous dropdownlist to try and set the selected value of this drop down list. (And yes, the previous dropdownlist has the same elements in it as this one does).

Thanks for responding.

[WebMethod]public static CascadingDropDownNameValue[] GetTestKeys(string knownCategoryValues,string category) {StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);if (!kv.ContainsKey("officeType") || String.IsNullOrEmpty(kv["officeType"])) {return null;}OracleCommand cmdGetTestKeys =new OracleCommand(@."SELECT test_key, test_key || ' ' || test_orgn || ' ' || test_subj as description FROM linc.pccdb_ttestWHERE test_user = :p_OfficeORDER BY test_key",new OracleConnection(ConfigurationManager.ConnectionStrings["PCCDB_Web"].ConnectionString));cmdGetTestKeys.Parameters.AddWithValue("p_Office", kv["officeType"]);cmdGetTestKeys.Connection.Open();OracleDataReader drTestKeys = cmdGetTestKeys.ExecuteReader();List values =new List();Object[] keyValuePair =new Object[2];string value = String.Empty;while (drTestKeys.Read() ==true) {drTestKeys.GetValues(keyValuePair);value = Convert.ToInt32(keyValuePair[0]).ToString();//Check for the headerTestKey, if it exits then popluate the set for the header,//otherwise setup the detail test key to match the headerTestKey.if (!kv.ContainsKey("headerTestKey") || String.IsNullOrEmpty(kv["headerTestKey"])) {values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value));}else {if (value == kv["headerTestKey"]) {values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value,true));}else {values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value));}}}cmdGetTestKeys.Connection.Close();return values.ToArray();}

From the initial look at your code, I would agree, it should work fine.

One thing I ran into, and fought for days because I was "SURE" I had it correct, was the key names. You may want to consider placing some debug statements around the "IF/ELSE" logic to see exactly what part of the code is being hit. I placed some breakpoints in my code and examined the key collection. I found I was looking for the incorrect key name and thus never hitting the code I was thinking it was hitting. I know that sounds basic, but from looking at your code it should work, due to the fact it is not working, I am guessing it may not be hitting the code you expect.

I would examine the flow around this section and make 100% sure the key you are looking for "headerTestKey" really exists in the key collection.

If this does not work, post you entire webserice and I will take a look at it and try to recreate the problem on my side.

Good Luck...

if (!kv.ContainsKey("headerTestKey") || String.IsNullOrEmpty(kv["headerTestKey"])) {
values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value));
}
else {
if (value == kv["headerTestKey"]) {
values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value,true));
}
else {
values.Add(new CascadingDropDownNameValue((string)keyValuePair[1],value));
}
}


this almost works for me. Almost...

I have a gridview on my page and when i click on edit command of gridview row, three dropdowns have to be populated with default value based on row data.

So gridview_rowediting is called firstly. I declare contextkeys for all of my dropdowns here.

Next, WebMethods do their job. I found out they do it properly while debbuging.

But the problem is that only first time calling "edit" this works. Then there are always same items choosen. Seems strange because webmethods do their job.

What could be wrong?


Some things you may try... (You may have already tried these items)

1. Make sure each time your gridview_rowediting fires, that the context keys are being set with the values you are expecting. I knwo, from working with GridViews in the past, that you have to be careful to get the correct row values.

CascadingDropDownGroupType.ContextKey = dr2["GRPLKUPiGroupType"].ToString();

CascadingDropDownGroup.ContextKey = dr2["GRPLKUPsGroupCode"].ToString();

2. Once you have verified the ContextKeys are being set properly, make sure the are correctly set inside the WebMethod. Just to make sure nothing got hosed up in the passing of the ContextKeys.

Just display / examine thecontextKey.ToString().Trim() to make sure each of them are properly set based on the data from the row edit.

3. Make sure you aer setting the DEFAULT VALUE is TRUE for the matching ContextKey Value.

if (Convert.ToInt32(contextKey.ToString()) == iTheGroupTypeId)

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),true));

}

else

{

values.Add(newCascadingDropDownNameValue(sTheGroupType, iTheGroupTypeId.ToString(),false));

}

4. Make sure the values passed from one WebMethod to the other is set / used correctly. For example, I have 2 CDDL in my code. One is Group Type and the other is Group. In the 2nd WebMethod I use the following to get the value passed from the 1st WebMethod. Verify you have this set in your code from WebMethod to WebMethod and make sure the highlighted items "out" is being set correctly.

StringDictionary kv =CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

int iTheGroupTypeId = -1;

if (!kv.ContainsKey("GroupType") || !Int32.TryParse(kv["GroupType"],out iTheGroupTypeId))

{

returnnull;

}

I hope this helps.. If not, post your complete WebService code and I will do what I can to try and look at it and help you out.

Best of Luck... Cool


As I said, i debbuged the web service and checked all these things. There are no problems with contexKey - it allways holds the value needed. So the code

For Each row As DataRow In gds.Tables(0).Rows
If cint(row("id_project")) = cint(contextKey) Then
values.Add(New CascadingDropDownNameValue( _
row("name"), row("id_project"), True))
Else
values.Add(New CascadingDropDownNameValue( _
row("name"), row("id_project"), False))
End If
Next

always "finds" the item needed. It's just not displayed then...


it works now. I had to put

dropdownlist.SelectedValue = -1

for all my dropdowns in datagrid_RowEditing sub

Preserving the scroll position of a treeview in an update panel

Hi There,

I have a treeview control in a panel with scrollbars. I want to preserve the scroll position and I have this code which works absolutely fine in firefox, but it doesn't in IE. Can somebody please get back to me, if you have experienced this problem and solved it.

Also I noticed that if I put an alert (commented), it works fine, which is absolutely weird.

Thanks a lot!!

<scripttype="text/javascript">

var scrollTop;

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function BeginRequestHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

scrollTop=elem.scrollTop;

}

function EndRequestHandler(sender, args)

{

//alert(scrollTop);

var elem = document.getElementById('<%= treePanel.ClientID %>');

elem.scrollTop = scrollTop;

}

</script>

I noticed one more weird thing. I have roles set up on this application. If a user is in the admin role, this works fine. But if the user is not in that role, then the scrolling is not preserved, whenever a node is selected. I have absolutely no idea why this is happening..This is the case only in IE. Firefox has no problem at all.

Any suggestions are greatly appreciated..

Thanks a lot!!


Change:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

to:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);

and change the name of your function. endRequest happens when control has been returned to the browser, but everything may not have been rendered on the page. Your code is getting ahead of itself.


Thanks a lot for your suggestion. It still doesn't work...thisis what I have..

<scripttype="text/javascript">

var scrollTop;

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);

function BeginRequestHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

scrollTop=elem.scrollTop;

}

function PageLoadedHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

elem.scrollTop = scrollTop;

}

</script>


IE evidently has difficult with scrollTop under certain DOCTYPE definitions.

Replace elem.scrollTop = scrollTop; with

elem.scrollTo(0,scrollTop);


Unfortunately, scrollTo is not recognized in IE 7. I am not sure about IE 6.

As I have mentioned earlier, there is one more weird thing. I have roles set up on this application. If a user is in the admin role, this (script with scrollTop) works fine. But if the user is not in that role, then the scrolling is not preserved, whenever a node is selected. I have absolutely no idea why this is happening..This is the case only in IE. Firefox has no problem at all.

Thanks.


http://www.eggheadcafe.com/tutorials/aspnet/7dd57635-0587-42ba-ae73-f52449e653bf/aspnet-ajax-maintain-scr.aspx

http://forums.asp.net/p/1150033/1873660.aspx

http://aspnet.4guysfromrolla.com/articles/111704-1.aspx

<pages smartNavigation="true"MaintainScrollPositionOnPostback="true"/>

Usually People loves to maintain the scroll postiion. But requirment is reverse, Here is the trick, create an script tag after the scriptmanager and put the following lines:

<script type="text/javascript">var prm = Sys.WebForms.PageRequestManager.getInstance();prm.add_beginRequest(beginRequest);function beginRequest(){ prm._scrollPosition = null;}</script> 

Let me know if this helpful to you


I got this working from the links in the second link you have posted..

I have onscroll="javascript:saveScroll();" on the panel and..

<script type='text/javascript'>
var scrollLeft = 0;

function setScroll()
{
if(document.getElementById('<%= Panel1.ClientID %>').scrollLeft != scrollLeft)
{
document.getElementById('<%= Panel1.ClientID %>').scrollLeft = scrollLeft;
}
}

function saveScroll()
{
scrollLeft = document.getElementById('<%= Panel1.ClientID %>').scrollLeft;
}
</script>

The condition forces the scrolling..

Thanks a lot.

Also thanks to Mr. Budda for his suggestions...

Prevent child control inside the updatepanel to refresh the updatepanel

let say i have 2 UpdatePanels UP1 and UP2. Up1 contains a dropdownlist with 3000 items. When selectedindex of the dropdownlist is changed, it fires a partial postback to refresh the controls inside the UP2 which uses trigger. but at the same time it also refreshes the UP1which i want to avoid. and i also need this dropdown list to be inside the Updatepanel because the selected index is changing during partial postback.

Currently what i have done is i took this dropdownList out of updatepanel and the UP2 gets refreshed using trigger of that dropdownlist, and when it is required to update the the dropdown list i 'm injecting the javascript code in partial postback to do this.

any better work around to achieve this.

Thanks in Advance

RG

Pushed...

Preventing an UpdatePanel rendering after a Postback

Hi Everyone,

I have a page with three UpdatePanels, let's call them A, B and C and I have a control in B (a webgrid from ComponentArt) which issues a postback when one of it's rows is selected. What I would like to happen is for that event to be processed on the server, however I only want C to update its display (because in B, that row in the grid automatically changes it's appearance, so there is no need for the grid to be redrawn). Do you know if this is possible, ie to switch off the normally-useful behaviour of Atlas always refreshing the UpdatePanel containing the control that triggered the postback.

Thanks for any helpSmile [:)]

Rob.

Try insert Mode=Conditional in the Properties of UpdatePanel.

Bye.


Thanks for replying Paulo, however the mode is already set to "Conditional" for all of the UpdatePanels.


Sorry, but I don't think it's really possible.

You can cause 'C' to update by calling the Update method on that UpdatePanel in code behind, but if 'B' is causing the postback due to an event firing within it, 'B' is going to either force a full postback if its not in an UpdatePanel or a partial postback if its contained within an UpdatePanel.

The only idea I have is to change from the postback occurring on a row selected to a JavaScript command or something like tied to the onclick event to change the appearance of the row and then click a hidden button through JavaScript or something like that to cause 'C' to postback.

A partial postback is a lot like a regular postback and there's a difference in the parameter of the Render methods that determines what Html is sent back down to the browser.(Check out my blog posting on the subject.)

- Joel

I think this could be helpful (http://forums.asp.net/thread/1266249.aspx). I don't know if it's really what are you looking for but try it. I had a similar problem. I wanted to update panel B when I click on control in update panel A. The solution described in the thread works (and is very simple).

Pavel

Preventing onTextChanged event

I have a small conundrum with a databound textbox and an AJAX Masked Edit Extender control that formats the textbox input to a date. My problem is that I need to confirm user input on a control and send an email if a date is added to the box, I am using the textbox OnTextChange event to send the notification when the page is posted. However, if a date has already been entered, the Ajax control reformats the date captured from the database and causes the OnTextChanged event for the textbox to fire. I only want that event to fire if a user puts a date in that field not if the field is reformatted by the AJAX control.I am at a loss as to how to prevent the control from firing that event considering it is actually changing the text.

Thanks for any help,

I recommend using Teleriks Input control. Then you need zero programming for this. Its worth the grand if you doing this professionally.

Probblem with Menu control inside an update panel

Hi,

I have a master page with a script manager ,update panel and Content Palce Holder. in the default page which uses the masterpage I have added a menu control, textbox and a button. I have two problems which I have seen in the past in other versions of ajax. I have not coded anything other than just these controls on a page

1) I could click on button all day long and there is no java script error but as soon as I click on a menu item I get javascript error saying:

Line:221

Char:20

Error '0.cells' is null or not an object

code: 0

2) I can not get my CSS sheet work in my app theme for the background images. I have the following code in my CSS

.Menu1BackGround

{

background-image:url(/Images/Menu1_Background.bmp);

}

and I have assigned the it to the menu. Nothing happens as if it does not recognize the image path. I could add the background:black to the code and it works fine for the color but not the image. I am not sure if thisis because of the same problem.

Any body have any ideas?

Thanks

Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls. The Menu control is not supported inside an UpdatePanel.

I have been using this piece of javascript to go around the menu problem:

var oldMenu_HideItems = Menu_HideItems;if(oldMenu_HideItems){Menu_HideItems = function(items){if (!items || ((typeof(items.tagName) =="undefined") && (items instanceof Event))) { items = __rootMenuItem; }if(items && items.rows && items.rows.length == 0){ items.insertRow(0); }return oldMenu_HideItems(items);} }
I got it from the asp:menu javascript code and I hook it to "patch" the problem.
Adding it to a page where a menu resides makes the javascript error go away. 

http://forums.asp.net/thread/1517884.aspx

HTH


Menu control is not compatable with AJAX.

I m also facing sme problem..

Probelms with Modal Popup via server in code behind

Hi all

I am having problems while adding the modal popup dynamically to my page on the server side on a (web user control). When I set the "TargetControlId" or the "PopupControlId" like this -

ModalPopupExtender modPop = new ModalPopupExtender();
TextBox tbMsg = new TextBox();
tbMsg.ID = "tbMsg";
tbMsg.Text = "Thanks!";
modPop.ID = "modulePopup";
modPop.TargetControlID = hiddenField.ID; //made this hidden field in the user control
modPop.PopupControlID = tbMsg.ClientID;
modPop.BackgroundCssClass = "modalBackground";
modPop.X = 200;
modPop.Y = 200;

Now what is happening is that the ID's that go to the modal popup javascript (ScriptResource etc) I see that it goes in as the name of the textbox itself "tbmsg" instead of the client ID ? so I see something like document.getElementByID("tbMsg") !!!

What am I supposed to do??

Thanks in advance

Sanchita

hiddenField.ClientID will get the ID which is generated by ASP.net

Proble with Accordion Control and user control

There is one problem with Accordion Conrol

I place use control in ContentTemplate of Accordion Control.

Now problem is that when Accordion Control load first HeaderTemplate Load then page load event of User control which i placed in ContentTemplate fire.

So this is problem.

Please help me.

Thanks in advance.

Not sure at what your trying to get at here, but see if this page helps.

http://asp.net/ajax/control-toolkit/live/Accordion/Accordion.aspx


Hi Piyushp,

piyushp:

Now problem is that when Accordion Control load first HeaderTemplate Load then page load event of User control which i placed in ContentTemplate fire.

It is normal to say so. Based on the order of execution, the inner contronl's pageLoad event will be occurred before the outer control(or container)'s.

Best regards,

Jonathan.

PROBLEM - Timer Control calling Web Service?

Hi,

I have an issue, where I need to utiliize the AJAX Timer Control to continously poll an AJAX Web Service. Now I have successfully been calling the Web Service directly from Javascript, without any issue, however I need to perform some server-side actions.

Hence i need to use the Timer control to perform a onTick event call, which uses the same AJAX Web Service on the server side as follows:

iWebService ws = new iWebService();

string response = ws.iFunction("some data");

The problem here is i recieve the following error on every interval call from the Timer;

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

If anyone can help here, then that would be great, otherwise a temporary solution for my problem is to get the Timer to call a client side function instead of the server side one, and then for me to make a traditional Javascript request to the Web Service. If anyone knows how to do this, I would be very greatful.

Thank you!

We'd need to see some code to figure out what's going on, but rather than using the server Timer control, you're probably better off downloading the Futures January CTP and using the Sys.Preview.Timer control in there.

Hi, Steve

<formid="mainform"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"><Services><asp:ServiceReferencePath="iWebService.asmx"/></Services></asp:ScriptManager><asp:Timerid="timToolBar"runat="server"OnTick="Refresher"Interval="5000"></asp:Timer><asp:UpdatePanelID="upToolBar"runat="server"UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTriggerControlID="timToolBar"/></Triggers><ContentTemplate><uc2:ctrlToolBarID="ToolBar"runat="server"/></ContentTemplate></asp:UpdatePanel>
//CODE BEHIND FILE 

protected void Refresher(object sender, EventArgs e)

{

iMediaService ws =newiMediaService();

string response = ws.GetEvent(sessionid.Value, 2000);

//Some code here to update the Toolbar

}

It's pretty simple to be honest, the call to the WS basically returns some info I use to update the ToolBar. I need to call the WS continuosly, but information is only returned if the iWebService.RegisterClient is called first, before this, the call to GetEvent returns an empty string, which is correct. But after the RegisterClient has been called, i should get some data back from every call to the ws.GetEvent function.

Simple Call Logic

1. Register Client

2. Repeat call to GetEvent & Update ToolBar

The first call to GetEvent after the RegisterClient works fine and i recieve the correct data, but after that, when the Timer fires every interval, i get that error message. The ToolBar is a Web User Control, now simply I could just output the response string from GetEvent to a TextBox for testing, but like i said, the first call is fine, after that it just throws that error.

Also as i was debugging this, the debugger was not breaking on my breakpoint on the first line of the Refresher function, i think theres a problem after i write some info to the ToolBar.


The 500 suggests that something's breaking on the server. I would recommend grabbingNikhil's Web Development Helper and taking a look at the request and 500 response. It's quite likely the contents of the response will show you exactly what the problem is.

(As it is, I can't really guess what's going wrong.)

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/