Showing posts with label selected. Show all posts
Showing posts with label selected. Show all posts

Wednesday, March 28, 2012

PostBack once all lists in CascadingDropDown are selected

Has anyone found a way to generate a postback once all lists in a CascadingDropDown have a valid selection.

I am converting a web app that has many places where the user has to select Software, Version, Terrain and Course (It's a Virtual Reality Cycling Portal) Previously each selection caused a postback to populate the next list. On each post back the state of the page may need to changed, in terms of different controls being visible to capture either the riders time or the distance they cover.

I have switched to using Atlas and created a UserControl with the CDD to reduce the postbacks, but I still need to change the state of the controls with a postback, as I need to lookup details of the course to determine which controls should be visible.

So what I need to do is generate a postback once all lists have a valid selection. As a last resort I can turn the Ride Upload tool I am referring to into a wizard, but I would prefer to keep the new UI similar to the original single form one users are already using.

The user control is working great in all but this one scenario, as the other scenarios all require the user to click on a button to trigger the update of a data control.

Once the last CDD gets a selection, you know that all the CDDs have a selection - might you be able to tag the last CDD with AutoPostBack? Alternatively, maybe you could write a little bit of JS to run on the client side and hook the onchange event of the DDL and do the postback manually?

PostBack Problem, Need Help.

I have a page with a drop down that drives a gridview. Now whatever is selected the drop down will drive whats shown in the gridview. The page loads fine and the default value in the drop down loads the gridview fine. Now on each row in the gridview I have an edit button to edit that row. I use a modal popup to edit that row and save it. The modal works great and updates a row. Here is where the problem happens, if I change the drop down to a different value the gridview updates, I edit the row and the modal pop is ok and saves...but without changing the drop down again if I try to edit another row I get this error...

--------
Windows Internet Explorer
--------
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@dotnet.itags.org. Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
--------
OK
--------

Now I have tried adding that attrbute to the page tag and it still does not work...it gives me a similar error than the above one. I assume it has something to do with having all these postbacks and the modal is causing one while so is the edit button and they are conflicting somehow...anyway, any direction or solution would great. Let me know if anyone needs to see some code.

Hi Horizon,

In your modal popup, do you make partial or full postback when you update the datagrid row?

If you make partial postback, there is chance the server does not know all about this partial update, especially if you modify or update portions of your page, so by the next time you try to issue partial postback the server will complain about invalid postback event arguments.

It works if you change the dropdown because the dropdown issues full postback so the server now knows about all modifications on your page.

Is it an option to issue a full postback when you update the rows in the datagrid?

If your application does not require high grades of security, you could turn off the enableEventValidation attribute globally for your application (in web.config file).

Probably some ASPX and code-behind code would be helpful here to see how exactly you do the postbacks and updates on your page...

Kind regards,

sbogus.


Thanks you lead me on the right path, I added this to the load event...

ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);

What this does is cause a full post back on the page now when I click btnSaveRankings which is in my modal panel. Though know its not saving state on my drop down...it reverts it back to the value as if you just came into the site...I am going to post my aspx and aspx.cs file...

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="PowerRankingsAjax.admin.index" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Add/Edit Power Rankings</title> <link href="../ModalDialogs.css" rel="stylesheet" type="text/css" /></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="lblError" runat="server" Text=""></asp:Label> <ajaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxControlToolkit:ToolkitScriptManager> Edit Past Issues <br /> Select Issue: <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlIssue_SelectedIndexChanged"></asp:DropDownList> <br /> <asp:UpdatePanel ID="uEditPanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"> <ContentTemplate> <asp:GridView ID="EditPowerRankings" runat="server" AutoGenerateColumns="false" OnRowCreated="EditPowerRankings_OnRowCreated" > <Columns><asp:TemplateField ShowHeader="False"><ItemTemplate> <asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" CausesValidation="false" /></ItemTemplate></asp:TemplateField><asp:BoundField DataField="pid" /><asp:BoundField DataField="teamabbr" /><asp:BoundField DataField="team" HeaderText="Team" SortExpression="team" /><asp:BoundField DataField="rank" HeaderText="Rank" SortExpression="rank" /><asp:BoundField DataField="comment" HeaderText="Comment" SortExpression="comment" /></Columns> </asp:GridView><!--cheesy button for the modal popups target control--> <asp:Button ID="btnHiddenRankings" runat="server" style="display: none" /> <ajaxControlToolkit:ModalPopupExtender ID="mpeRankings" runat="server" TargetControlID="btnHiddenRankings" PopupControlID="pnlRankings" CancelControlID="btnCancelRankings" BackgroundCssClass="modalBackground" Drag="true" > </ajaxControlToolkit:ModalPopupExtender> <asp:Panel ID="pnlRankings" runat="server" CssClass="modalBox" Style="display: none;" Width="500px"><asp:Panel ID="RankingsCaption" runat="server" CssClass="caption" Style="margin-bottom: 10px;">Edit Rankings</asp:Panel> <asp:HiddenField ID="hidRankEditIndex" runat="server" Value="-1" /><div class="divCol"></div><div class="divColLast"> <asp:Image ID="imgTeam" runat="server" />  <asp:Label ID="lblTeamName" runat="server" Text=""></asp:Label></div><div class="clearer"></div><div class="divCol">Rank:</div><div class="divColLast">   <asp:DropDownList ID="ddlEditRank" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> <asp:ListItem>7</asp:ListItem> <asp:ListItem>8</asp:ListItem> <asp:ListItem>9</asp:ListItem> <asp:ListItem>10</asp:ListItem> <asp:ListItem>11</asp:ListItem> <asp:ListItem>12</asp:ListItem> <asp:ListItem>13</asp:ListItem> <asp:ListItem>14</asp:ListItem> <asp:ListItem>15</asp:ListItem> <asp:ListItem>16</asp:ListItem> <asp:ListItem>17</asp:ListItem> <asp:ListItem>18</asp:ListItem> <asp:ListItem>19</asp:ListItem> <asp:ListItem>20</asp:ListItem> <asp:ListItem>21</asp:ListItem> <asp:ListItem>22</asp:ListItem> <asp:ListItem>23</asp:ListItem> <asp:ListItem>24</asp:ListItem> <asp:ListItem>25</asp:ListItem> <asp:ListItem>26</asp:ListItem> <asp:ListItem>27</asp:ListItem> <asp:ListItem>28</asp:ListItem> <asp:ListItem>29</asp:ListItem> <asp:ListItem>30</asp:ListItem> </asp:DropDownList></div><div class="clearer"></div><div class="divCol">Comments:</div><div class="divColLast"> <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine" MaxLength="500" Width="480" Height="200"></asp:TextBox></div><div class="clearer"></div><div style="white-space: nowrap; text-align: center;"> <asp:Button ID="btnSaveRankings" runat="server" Text="Save" OnClick="btnSaveRankings_Click" CausesValidation="true" /> <asp:Button ID="btnCancelRankings" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancelRankings_Click" /></div></asp:Panel> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlIssue" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form></body></html>

cs file...

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace PowerRankingsAjax.admin{public partialclass index : System.Web.UI.Page { powerrankings oPowerrankings =new powerrankings(); DataSet ds =new DataSet();public String strWeek;public int intCountVal;protected void Page_Load(object sender, EventArgs e) { ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSaveRankings);if (oPowerrankings.ConnectToDatabase(lblError) ==true) {if (!Page.IsPostBack) {//GetWeek GetWeek(); BuildEditList(); BuildEditGrid(strWeek); } } ds.Dispose(); }protected void GetWeek() {//Current Week strWeek = oPowerrankings.GetMaxWeek(ds, lblError); }protected void BuildEditList() { ddlIssue.DataSource = ds.Tables[oPowerrankings.GetAllWeeks(ds, lblError).ToString()]; ddlIssue.DataTextField ="week"; ddlIssue.DataValueField ="week"; ddlIssue.DataBind(); intCountVal = oPowerrankings.GetHolder(ds, lblError);if(intCountVal > 0) { ListItem li =new ListItem("Edit","edit"); ddlIssue.Items.Add(li); }else { ListItem li =new ListItem("New","new"); ddlIssue.Items.Add(li); } lblError.Text = intCountVal.ToString();//ddlIssue.SelectedValue = strWeek; }protected void BuildEditGrid(string strWeek) { EditPowerRankings.DataSource = ds.Tables[oPowerrankings.GetEditPowerRankings(strWeek, ds, lblError).ToString()]; EditPowerRankings.DataBind(); }protected void ddlIssue_SelectedIndexChanged(object sender, EventArgs e) { strWeek = ddlIssue.SelectedValue;if (oPowerrankings.isNumeric(strWeek, System.Globalization.NumberStyles.Integer)) { BuildEditGrid(strWeek); }else { } }protected void EditPowerRankings_OnRowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[1].Visible =false; e.Row.Cells[2].Visible =false; }protected void btnSaveRankings_Click(object sender, EventArgs e) { oPowerrankings.UpdatePowerRankings(Convert.ToInt16(hidRankEditIndex.Value), Convert.ToInt16(ddlEditRank.SelectedValue), txtComment.Text, lblError); mpeRankings.Hide(); strWeek = ddlIssue.SelectedValue; BuildEditList(); BuildEditGrid(strWeek); uEditPanel.Update(); }protected void btnCancelRankings_Click(object sender, EventArgs e) { mpeRankings.Hide(); }protected void btnEdit_Click(object sender, EventArgs e) { Button btnEdit = senderas Button; GridViewRow row = (GridViewRow)btnEdit.NamingContainer; hidRankEditIndex.Value = row.Cells[1].Text; imgTeam.ImageUrl ="../images/" + row.Cells[2].Text +".gif"; lblTeamName.Text = row.Cells[3].Text; ddlEditRank.SelectedValue = row.Cells[4].Text; txtComment.Text = row.Cells[5].Text; uEditPanel.Update(); mpeRankings.Show(); } }}

Pre selected item in a cascading dropdownlist

I have a set of 3 dropdowns that im using the cascading dropdownlist ajax with. They all load corectly with the webservice and work great, but the form is an inventory entry screen and I need to update an existing inventory sometimes. So is there a way to pre-select all 3 dropdown list boxes? I tried "CascadingDropDown1.SelectedValue = "MACK";" but it gets erased when the webservise returns the data.


Maybe you got it solve by the date, but i figure out a way to lead with cascadingDropdownlist and preselection.
In my case I have 3 dropdownlist (ddl) inside a formview and depending is a session variable is already filled the value for the first DDL (parent) is changed.

In the following code, FvwPostOff is a formview which contents my DDL and CascadingDropDown (CddBuilding) extenders. The thing is to set the value by the CascadingDropdown extender instead of the DDL direclty:

ElseIf (Session("BUILD_NB") IsNotNothing)Then Try Dim CddBuildingAs CascadingDropDown = FvwPostOff.FindControl("CddBuilding") CddBuilding.SelectedValue = Session("BUILD_NB")Catch exAs IndexOutOfRangeException' nothingEnd Try End If
Hope this help

Saturday, March 24, 2012

Problem getting SelectedIndex from CascadingDropDown in an UpdatePanel

Hey everyone, I'm having an issue with my AJAX page. I have a CascadingDropDown that once a value is selected, trigger the population of another CascadingDropDown that resides in an UpdatePanel. I'm attempting to have the second CascadingDropDown populate a textbox based on its .SelectedIndex. For some reason, I can grab the .SelectedValue, but getting .SelectedIndex always returns 0.

Does anyone else have this problem, or know how to solve it. Any help would be greatly appreciated.

Did you find a solution for your problem? Coz I also have the same problem

hi,

please refer :http://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspx

please post the code, so that i can help you to solve your problem.

Thanks

Kishore.

www.relgo.com


hello invisible man,

thanks for the reply, here is my scenario... i have two cascadingdropdown control on my page, and then I have a dynamicpopulate control (which is binded or the targetcontrol is a textbox) that is dependent on the selected value of the two cascadingdropdown control. The problem is passing the value of both the cascadeddropdown control to the dynamicpopulate control.

here is my aspx code (i did not include the master page)

123<%@.4Page Language="C#"5MasterPageFile="~/NOCMasterPage.master"6AutoEventWireup="true"7CodeFile="ApplicationForm.aspx.cs"8Inherits="ApplicationForm"9Title="Sharjah NOC Application Form"10EnableEventValidation="false" %>1112<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>1314"ApplicationFormContent" ContentPlaceHolderID="cphNOCMasterPage" Runat="Server">15 "smApplicationForm" runat="server">1617 "text/javascript">18 function SelectFromDDL(ddPlotNumberID, ddAreaNameID)19 {20 alert(document.getElementsByName(ddPlotNumberID));21 var e = document.getElementsByName(ddPlotNumberID);// get ddPlotNumber element22 alert(eval([e.selectedIndex].text));2324 }2526 function fnContextValue(strSelectedAreaNameSelectedPlotNo)27 {28 var behaviorId = $find('dpePlotAreaID');29if (behaviorId)30 {31 behaviorId.populate(strSelectedAreaNameSelectedPlotNo);32 }3334 }3536

3738 39 "lblAreaName" runat="server" Text="Area Name" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">40 "ddAreaName" runat="server" EnableViewState="false">4142 "cddAreaName" runat="server"43 PromptText="Please select the Area in Manhattan"44 LoadingText="Loading ...."45 TargetControlID="ddAreaName"46 ServicePath ="PlotAreaService.asmx"47 ServiceMethod ="GetAreaName"48 Category="AreaName">4950

51

52 53 "lblPlotNumber" runat="server" Text="Plot Number" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">54 55 "ddPlotNumber" runat="server">565758 "cddPlotNo" runat="server"59 TargetControlID="ddPlotNumber"60 ParentControlID="ddAreaName"61 PromptText="Please select Plot Number inside the selected Area"62 ServicePath ="PlotAreaService.asmx"63 ServiceMethod ="GetPlotNo" Category="PlotNo">6465

66

67 68 "lblPlotArea" runat="server" Text="Area of Plot" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">69 70 "txtPlotArea" runat="server" Width="205px">71 "dpePlotArea" runat="server"72 ServicePath="PlotAreaService.asmx"73 ServiceMethod="GetPlotArea"74 TargetControlID="txtPlotArea"75 ContextKey=""76 ClearContentsDuringUpdate="true"77 BehaviorID="dpePlotAreaID">787980

8182838485page code behind8687using System;88using System.Data;89using System.Configuration;90using System.Collections;91using System.Web;92using System.Web.Security;93using System.Web.UI;94using System.Web.UI.WebControls;95using System.Web.UI.WebControls.WebParts;96using System.Web.UI.HtmlControls;97using System.Data.OleDb;98using System.Data.SqlClient;99using System.Collections.Specialized;100using System.Workflow.Runtime;101using System.Workflow.Runtime.Hosting;102using AjaxControlToolkit;103104105public partialclass ApplicationForm : System.Web.UI.Page106// Use BasePage.cs as code file for parameter getting and107// access to Module.cs108//public partial class ApplicationForm : BasePage109{110protected void Page_Load(object sender, EventArgs e)111 {112113string strPlotNumberID ="ctl00_cphNOCMasterPage_cddPlotNo_ClientState";114//string strAreaNameID = cddAreaName.ID;115 // CascadingAreaName Id not the dropdown116string strAreaNameID ="ctl00_cphNOCMasterPage_cddAreaName_ClientState";117 ddPlotNumber.Attributes.Add("OnChange","return SelectFromDDL(" + strPlotNumberID +"," + strAreaNameID +" )");118 }119120121}122123124125web service code126127using System;128using System.Web;129using System.Collections;130using System.Collections.Specialized;131using System.Collections.Generic;132using System.Xml;133using System.Web.Services;134using System.Web.Services.Protocols;135using System.Data;136using System.Data.OleDb;137using System.Data.SqlClient;138using AjaxControlToolkit;139140/// <summary>141/// Summary description for PlotAreaService142/// </summary>143[WebService(Namespace ="http://tempuri.org/")]144[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]145[System.Web.Script.Services.ScriptService]146public class PlotAreaService : System.Web.Services.WebService147{148 string strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=****data table name ******;Data Source=*** Database Server Instance name****";149 string strTableName = "dbo.sharjah_area_name";150 string fldAreaName = "area_name";151 string fldPlotNo = "area_plot_number";152 string fldAreaOfPlot = "area_of_plot";153154public PlotAreaService()155 {156157//Uncomment the following line if using designed components158 //InitializeComponent();159 }160161162/*************************************163 * Required by cascading drop down164 * parameter name and type should not be changed165 * ***********************************/166 [WebMethod]167public CascadingDropDownNameValue[] GetAreaName(string knownCategoryValues,string category)168 {169170 dsAreaNameTableAdapters.sharjah_area_nameTableAdapter objAreaNameAdapter =new dsAreaNameTableAdapters.sharjah_area_nameTableAdapter();171 List lstAreaName =new List();172173foreach (DataRow drAreaNameTempin objAreaNameAdapter.dtGetDataAreaName())174 {175string strAreaName = drAreaNameTemp[fldAreaName].ToString();176 lstAreaName.Add(new CascadingDropDownNameValue(strAreaName, strAreaName));177178 }179180return lstAreaName.ToArray();181 }182183 [WebMethod]184public CascadingDropDownNameValue[] GetPlotNo(string knownCategoryValues,string category)185186 {187string[] arrChosenAreaName = knownCategoryValues.Split(':',';');188string strChosenAreaName = arrChosenAreaName[1];189 dsPlotNoTableAdapters.sharjah_area_nameTableAdapter objPlotNoAdapter =new dsPlotNoTableAdapters.sharjah_area_nameTableAdapter();190 List lstPlotNo =new List();191foreach (DataRow drPlotNoin objPlotNoAdapter.dtPlotNoData(strChosenAreaName))192 {193string strPlotNo = drPlotNo[fldPlotNo].ToString();194 lstPlotNo.Add(new CascadingDropDownNameValue(strPlotNo, strPlotNo));195196 }197return lstPlotNo.ToArray();198 }199200 [WebMethod]201public string GetPlotArea(string contextKey)202 {203 System.Threading.Thread.Sleep(250);204string strPlotArea =string.Empty;205string[] arrContextKey = contextKey.Split(',');206string strAreaName = arrContextKey[0];207string strPlotNo = arrContextKey[1];208 dsPlotAreaTableAdapters.sharjah_area_nameTableAdapter objPlotAreaAdapter =new dsPlotAreaTableAdapters.sharjah_area_nameTableAdapter();209210foreach (DataRow drPlotAreain objPlotAreaAdapter.dtPlotAreaData(strAreaName, strPlotNo))211 {212 strPlotArea = drPlotArea[fldAreaOfPlot].ToString();213 }214return strPlotArea;215 }216}217218219220