Showing posts with label forms. Show all posts
Showing posts with label forms. Show all posts

Monday, March 26, 2012

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.

pressing enter on a form in an updatepanel

Hi,

Im trying to fix my forms so that enter does not submit forms on IE/Mozilla/Safari but cannot find a solution. First off I used :

/*--- Disable enter key ----*/function kH(e) { var pK = e ? e.which : window.event.keyCode;return pK != 13;} document.onkeypress = kH;if (document.layers) document.captureEvents(Event.KEYPRESS);/*------------*/

on all pages but it didnt seem to work. So then I decided to try catch the keypress from forms like input and textarea and I used the following (onkeypress="return ifEnter(this,event);")

function ifEnter(field,event) { var theCode =event.keyCode ?event.keyCode :event.which ?event.which :event.charCode;if (theCode == 13) {return false; }else {return true; }}

but again it doesnt seem to work. Another thing I noticed is that it seems to submit the form as asp.net would. My default form submission is a next button which moves to another page when submitted, but when someone hits enter, the same page reloads with a standard postback i think.

What I want to know is why the javascript wont work? Is it because the form is in an updatepanel? How can I manage the user pressing enter in an update panel?

Why doesnt the user pressing enter activate the DefaultButton action of the panel which its in?

All help much appreciated!

C

Edit: never mind, I see the behavior now.

I saw the behavior with only one textbox. Adding a second set to invisible, perhttp://aspnet.4guysfromrolla.com/articles/060805-1.aspx, fixed it.

See if that helps for you.


My form allready had multiple textboxes etc.

The problem seesm to be only in firefox. Ive found a partial fix for my problem which at least submits my default button and saves the form instead of performing a callback here :

http://www.andornot.com/about/developerblog/2007/09/fix-firefox-defaultbutton-issue-with.aspx

Im still looking for a simple way to prevent enter key form posting back in certain textareas or input text boxes in firefox pretty please.

Wednesday, March 21, 2012

Problem loading AJAX in login page

Hi All

My system uses Forms Authentication and in the Login page (first page) I get error in AJAX:

'Sys' is undefined
Sys.Application.initialize();

BUT after I enter, the next page (using AJAX too) opens correct without error AND if I return to login page, works too!
I think that is because after login, the other page create javascript files.. but the code of this pages is the same

So I want to know if this is a permission problem (because forms authentication maybe deny) or I need to do something for Login page create ajax files.

thanks! Oscar.

Could you mind posting your login page code.


LOGIN.aspx.Vb Code:

<formid="form1"runat="server"> <asp:ScriptManagerID="ScriptManager2"runat="server"></asp:ScriptManager> <asp:LabelID="Label1"runat="server"Font-Names="Verdana"Font-Size="Smaller"Style="position: static; top: 0px"Text="Username:"></asp:Label><asp:TextBoxID="txtUsername"runat="server"Style="position: relative;"></asp:TextBox><asp:LabelID="Label2"runat="server"Font-Names="Verdana"Font-Size="Smaller"Style="left: 0px; position: static; top: 0px"Text="Password:"></asp:Label><asp:TextBoxID="txtPassword" runat="server"Style="position: relative;"TextMode="Password"></asp:TextBox> <asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:ButtonID="btnSignIn"runat="server"Style="position: static"Text="Sign In"/><asp:PanelID="Panel1"runat="server"Height="50px"Style="position: static"Visible="False"Width="368px"><asp:TextBoxID="txtEmail"runat="server"Style="position: relative"></asp:TextBox> <asp:ButtonID="btnRecover"runat="server"Style="position: relative"Text="Send"/></asp:Panel>

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

***************************************************************************************

My web.Config:
<?xmlversion="1.0"?><configuration> <appSettings/> <connectionStrings/> <system.web> <compilationdebug="true"> <assemblies> <addassembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addassembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> </assemblies> </compilation> <authenticationmode="Forms"> <formsloginUrl="BackOffice/Login.aspx"defaultUrl="main.aspx"name="Passacaille"timeout="30"path="BackOffice/"/> </authentication> <authorization> <denyusers="?" /> </authorization> <pages> <controls> <addtagPrefix="asp"namespace="Microsoft.Web.UI"assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagPrefix="asp"namespace="Microsoft.Web.UI.Controls"assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </controls> <tagMapping> <addtagType="System.Web.UI.WebControls.CompareValidator"mappedTagType="Microsoft.Web.UI.Compatibility.CompareValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagType="System.Web.UI.WebControls.CustomValidator"mappedTagType="Microsoft.Web.UI.Compatibility.CustomValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagType="System.Web.UI.WebControls.RangeValidator"mappedTagType="Microsoft.Web.UI.Compatibility.RangeValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagType="System.Web.UI.WebControls.RegularExpressionValidator"mappedTagType="Microsoft.Web.UI.Compatibility.RegularExpressionValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagType="System.Web.UI.WebControls.RequiredFieldValidator"mappedTagType="Microsoft.Web.UI.Compatibility.RequiredFieldValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addtagType="System.Web.UI.WebControls.ValidationSummary"mappedTagType="Microsoft.Web.UI.Compatibility.ValidationSummary, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </tagMapping> </pages> <httpHandlers> <removeverb="*"path="*.asmx"/> <addverb="*"path="*.asmx"validate="false"type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addverb="GET"path="ScriptResource.axd"type="Microsoft.Web.Handlers.ScriptResourceHandler"validate="false"/> </httpHandlers> <httpModules> <addname="WebResourceCompression"type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <addname="ScriptModule"type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </httpModules> </system.web> <locationpath="BackOffice/Login.aspx"> <system.web> <authorization> <allowusers="?" /> </authorization> </system.web> </location> </configuration>


I believe that the problem still in web.config


The Problem is in your Login.aspx page, You forgot to put a ScriptManager.


There's a ScriptManager there.

My guess is that the deny authorization means the scripts (WebResource.axd, ScriptResource.axd) aren't being loaded. Try allowing those resources to get through?

You can easily tell if that's the problem by using Fiddler or Nikhil's Web Development Helper to monitor the HTTP traffic to see which request is failing.


Steve,
You're right, when I allow resources page works

This is the code that I added and now always generate javascript for asp.net

<locationpath="ScriptResource.axd">
<system.web>
<authorization>
<allowusers="?" />
</authorization>
</system.web>
</location>

thank you all