Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

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.

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.

preventing the tab index change if certain conditions exist

Hello,

I have a form with a tab panel control

Tab container name (client id) : Tabs

I would like to know how to set and prevent the tab from moving from index 0 if the request.querystring("pid") is empty or null.

Here is my current javascript:

<scripttype="text/javascript">function PanelClick(sender, e) {

var mpid = gup('pid');

if (mpid=="") {

SetActiveTab("Tabs",0);

}

}

function ActiveTabChanged(sender, e) {var mpid = gup('pid');

if (mpid=="") {

alert("Please choose a page or create a new page first");

returnfalse;

}

}

function SetActiveTab(tabControl, tabNumber)

{

var ctrl = $find(tabControl);

ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);

}

function gup( name ){name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

var regexS ="[\\?&]"+name+"=([^&#]*)";

var regex =new RegExp( regexS );

var results = regex.exec( window.location.href );

if( results ==null )return"";

else

return results[1];}

</script>

I guess all I need is the javascript reference to the active tab...

can anyone help me with this?

Ok, through a little more research, I found out how to navigate or prevent navigation of the tabs control via javascript:

Here's the code

<scripttype="text/javascript">

/

function ActiveTabChanged(sender, e) {

var mpid = gup('pid'); // get the querystring in the url by calling the gup function below... good little snippet for querystrings in javascript.

var activeTab = $get("Tabs"); // gets the element by the id of "Tabs" and defines the control variable activeTab.

activeTab.value = sender.get_activeTabIndex(); // gets the active tab index of the control.

if (mpid=="" && activeTab.value!=0) { // if the conditions aren't right then don't allow the user to navigate to any other tab.

alert("Please choose a page or create a new page first"); // alert the user.

SetActiveTab("Tabs",0); // sets the active tabreturnfalse; // doesn't allow the process to go to another tab.

}

}

function SetActiveTab(tabControl, tabNumber)

{

var ctrl = $find(tabControl);

ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);

}

function gup( name ){name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

var regexS ="[\\?&]"+name+"=([^&#]*)";

var regex =new RegExp( regexS );

var results = regex.exec( window.location.href );

if( results ==null )return"";

else

return results[1];}

</script>

I hope that the scripts above can help someone else.

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.

Wednesday, March 21, 2012

Problem loading saved data back into dropdownlist

I'm completely new to ASP.NET and Ajax, having quickly inherited a project from a consultant who is no longer with us.

Have a form with C# codebehind, and all this is running inside some Ajax components (tabcontainer and update panels). One dropdownlist (SystemID) determines the filtered values in a second dropdownlist (TypeID). In the page, there's the following to determine the source for each list:

<asp:SqlDataSourceID="sqlSystem"runat="server"

SelectCommand="Select Distinct '0' As SystemID, '(Select)' As Description From CMSSystem UNION

Select SystemID,Description From CMSSystem Where Active='1'">

</asp:SqlDataSource>

<asp:SqlDataSourceID="sqlType"runat="server"

SelectCommand="Select Distinct '0' As TypeID, '(Select)' As Description From CMSType UNION

Select TypeID, Description from CMSType Where SystemID = @dotnet.itags.org.SystemID">

<SelectParameters>

<asp:ControlParameterControlID="cboSystem"Name="SystemID"PropertyName="SelectedValue"/>

</SelectParameters>

</asp:SqlDataSource>

When I complete an empty form, the linking between the lists is fine. Select a value from SystemID, then I can select a value from TypeID that has been filtered.

The problem is on trying to load existing data. I have a procedure call inside Page_Load that loads existing values onto the form. Text boxes and checkboxes are just fine, and standalone dropdownlists are fine. I can load SystemID from a dataset row, but when I try to do the same for TypeID (trying to lookup the saved value in the list of filtered items), I find that the items collection is completely empty - and therefore, I get a null selectedvalue. What I'm guessing is that the SqlDataSource isn't "firing" (?) for the TypeID for some reason at the time of Page_Load, so I have no data to bind to the control.

Is that a good assumption, and if so, how can I get around this? I've been floundering around for a couple of weeks with this, and need any assistance I can get.

How about using the Page's Prerender event for that, instead of Load? Alternatively, you could handle theSqlDataSource's Selected event.


Didn't see any change with Page_PreRender instead of Page_Load.

I have this hunch that the SqlDataSource isn't being re-evaluated when I manually set the first dropdownlist's SelectedIndex (based on the previously saved, now retrieved, data). It must be a matter of timing or something. Trying to execute this codebehind:

if (dsRequestDetails.Tables[0].Rows[0]["SystemID"].ToString() !="")

{

liFind = cboSystem.Items.FindByValue(dsRequestDetails.Tables[0].Rows[0]["SystemID"].ToString());

cboSystem.SelectedIndex = cboSystem.Items.IndexOf(liFind);

}

if (dsRequestDetails.Tables[0].Rows[0]["TypeID"].ToString() !="")

{

liFind = cboType.Items.FindByValue(dsRequestDetails.Tables[0].Rows[0]["TypeID"].ToString());

cboType.SelectedIndex = cboType.Items.IndexOf(liFind);

}


populate the second dropdown at the ondatabound event of the first drop down. This will solve your problem