Maybe move the Xxx2 stuff out of the .isPostBack check and make sure you only do it during the proper wizard step?
yes,i did it, and this show me the record, but only show ,when i try to get data with :
DropDown2.SelectedItem.Text
it show "undefined"
and i have to change manually the selected item in internet explorer to another item and then return to the previous item to get the rigth item when i use:
DropDown2.SelectedItem.Text
Please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!
Is there a possibility that CascadingDropdown can be used without the use of web-services?
Thank you for an early reply.
rahul.2111@.gmail.com
Ok, this is the code, i'm using Pubs Data Base, in Page_Load event i fill a dataset with a record from employee, then set the job_id in CascadingDropDown_Job.SelectedValue, when i load step 2 set pub_id in CascadingDropDown_publisher.SelectedValue,then in step 1 and 2 i read the TEXT selected, but in step 3 i can't obtain the rigth DropDownList_Job.SelectedItem.Text and DropDownList_publisher.SelectedItem.Text, if i back to step 1 o 2 and select another item in de dropdownlist , when i return to step 3 now i read the rigth DropDownList_Job.SelectedItem.Text and DropDownList_publisher.SelectedItem.Text.
MyPage.aspx:
<%@. Page Language="VB" EnableEventValidation="false" %><%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@. ImportNamespace="System.Data.SqlClient" %><!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)If Not Page.IsPostBackThen Dim ConnectionAs New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True") Connection.Open()Dim CommandAs New SqlCommand("select * from employee where emp_id='PMA42628M'", Connection) Dim DataAdapter As New SqlDataAdapter(Command) Dim DataSet As New Data.DataSet DataAdapter.Fill(DataSet) Me.CascadingDropDown_Job.SelectedValue = DataSet.Tables(0).Rows(0)("job_id")'this line don't work, but i hope work in future release 'Me.CascadingDropDown_publisher.SelectedValue = DataSet.Tables(0).Rows(0)("pub_id") End If Page.DataBind() End Sub Protected Sub Wizard1_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Select Case Wizard1.ActiveStepIndex Case 1 If Me.PostBack_Step2.Value = "0" Then Dim Connection As New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True") Connection.Open() Dim Command As New SqlCommand("select * from employee where emp_id='PMA42628M'", Connection)Dim DataAdapterAs New SqlDataAdapter(Command)Dim DataSetAs New Data.DataSet DataAdapter.Fill(DataSet)'this line work fineMe.CascadingDropDown_publisher.SelectedValue = DataSet.Tables(0).Rows(0)("pub_id")'--------Me.PostBack_Step2.Value ="1"Else'ActiveStepChanged codeEnd If Case 2If Me.PostBack_Step3.Value ="0"Then'postback step3Me.PostBack_Step3.Value ="1"Else'ActiveStepChangedEnd If End Select End Sub</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Página sin título</title></head><body> <form id="form1" runat="server"> <div> <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="232px" Width="456px" OnActiveStepChanged="Wizard1_ActiveStepChanged"> <SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" /> <NavigationButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" /> <WizardSteps> <asp:WizardStep runat="server" StepType="Start" Title="Step 1"> <asp:DropDownList ID="DropDownList_Job" runat="server"> </asp:DropDownList> <br /> <br /> <cc1:CascadingDropDown ID="CascadingDropDown_Job" runat="server" BehaviorID="Wizard1_CascadingDropDown1" Enabled="True" TargetControlID="DropDownList_Job" ServiceMethod="Jobs" ServicePath="MyWebService.asmx" LoadingText="Loading..." PromptText="Select" Category="Job"> </cc1:CascadingDropDown> </asp:WizardStep> <asp:WizardStep runat="server" StepType="Step" Title="Step 2"> <asp:DropDownList ID="DropDownList_publisher" runat="server"> </asp:DropDownList> <cc1:CascadingDropDown ID="CascadingDropDown_publisher" runat="server" BehaviorID="Wizard1_CascadingDropDown_publisher" Category="Publisher" Enabled="True" LoadingText="Loading..." PromptText="Select" ServiceMethod="Publishers" ServicePath="MyWebService.asmx" TargetControlID="DropDownList_publisher"> </cc1:CascadingDropDown> </asp:WizardStep> <asp:WizardStep runat="server" StepType="Finish" Title="Step 3"> Job : <asp:Label ID="Label1" runat="server" Text='<%# DropDownList_Job.SelectedItem.Text %>'></asp:Label> <br /> CascadingDropDown_Job: <asp:Label ID="Label3" runat="server" Text='<%# CascadingDropDown_Job.SelectedValue %>'></asp:Label> <br /> <br /> Publisher: <asp:Label ID="Label2" runat="server" Text='<%# DropDownList_publisher.SelectedItem.Text %>'></asp:Label> <br /> CascadingDropDown_publisher: <asp:Label ID="Label4" runat="server" Text='<%# CascadingDropDown_publisher.SelectedValue %>'></asp:Label> </asp:WizardStep> </WizardSteps> <SideBarButtonStyle ForeColor="White" /> <HeaderStyle BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" /> </asp:Wizard> <br /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:HiddenField ID="PostBack_Step2" runat="server" Value="0" /> </div> <asp:HiddenField ID="PostBack_Step3" runat="server" /> </form></body></html>
MyWebService.asmx:
<%@. WebService Language="VB"Class="MyWebService" %>Imports System.WebImports System.Web.ServicesImports System.Web.Services.ProtocolsImports System.Data.SqlClientImports System.DataImports AjaxControlToolkitImports System.Collections.Generic<WebService(Namespace:="http://tempuri.org/")> _<Web.Script.Services.ScriptService()> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Public Class MyWebServiceInherits System.Web.Services.WebService <WebMethod()> _Public Function Jobs(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()Dim ConnectionAs New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True") Connection.Open()Dim CommandAs New SqlCommand("select job_desc, job_id from jobs", Connection)Dim DataAdapterAs New SqlDataAdapter(Command)Dim DataSetAs New Data.DataSet DataAdapter.Fill(DataSet)Dim ResultAs New List(Of CascadingDropDownNameValue)For Each rowAs DataRowIn DataSet.Tables(0).Rows Result.Add(New CascadingDropDownNameValue(row("job_desc"),CStr(row("job_id"))))Next Return Result.ToArray()End Function <WebMethod()> _Public Function Publishers(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()Dim ConnectionAs New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True") Connection.Open()Dim CommandAs New SqlCommand("select pub_name, pub_id from publishers ", Connection)Dim DataAdapterAs New SqlDataAdapter(Command)Dim DataSetAs New Data.DataSet DataAdapter.Fill(DataSet)Dim ResultAs New List(Of CascadingDropDownNameValue)For Each rowAs DataRowIn DataSet.Tables(0).Rows Result.Add(New CascadingDropDownNameValue(row("pub_name"),CStr(row("pub_id"))))Next Return Result.ToArray()End Function End Class
at the end in this posthttp://forums.asp.net/thread/1538386.aspx dhaligas has the same trouble, anybody has a fix to this bug?
a tip, if you write :
MyCascadeDropDown.SelectedValue="1:::SomeText"
the result is
MyDropDown.Selected=1
MyDropDown.SelectedItem.Text="SomeText"
with this tip dissaper the 'undefined', but you have to write a code that obtain the text
well i have to fix it my self, i will post the solution when finish the test
The fix I used to get the SelectedItem.Text value from the cascading drop down requires you to edit the CascadingDropDownBehavior.js file.
I updated the set_SelectedValue property so that it always gets set. The lines I changed are commented out. This will always return the SelectedText and Value.
set_SelectedValue :
function(value, text) {//if (this._selectedValue != value) {if (!text) {// Initial population by server; look for "value:::text" pairvar i = value.indexOf(':::');if (-1 != i) {text = value.slice(i + 3);
value = value.slice(0, i);
}
}
this._selectedValue = value;AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(
this,'set_ClientState', [this._selectedValue+':::'+text ]);this.raisePropertyChanged('SelectedValue');//}},
good, i fix it with this:
// Member variablesthis._parentElement =null;this._changeHandler =null;this._parentChangeHandler =null;this._lastParentValues =null;this._selectedValue =null;//added by rojascthis._selectedText=null;
and
set_SelectedValue : function(value, text) {if (this._selectedValue !=value) {// this run when the value changeif (!text) {// Initial population by server; look for "value:::text" pair var i =value.indexOf(':::');if (-1 != i) { text =value.slice(i + 3);value =value.slice(0, i); } }this._selectedValue =value;//added by Rojascthis._selectedText = text; AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(this,'set_ClientState', [this._selectedValue+':::'+text ]);this.raisePropertyChanged('SelectedValue'); }else{// this run when the text changeif(this._selectedText!=text){this._selectedText = text; AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(this,'set_ClientState', [this._selectedValue+':::'+text ]);this.raisePropertyChanged('SelectedValue'); }else{// put here anything that want to run when nothing change }//-------------- } },
I think that your and my fixs are little service pack for Ajax Toolkit
It seems like you are onto something here, but I'd like to understand the issue better first. Could you please update the sample above so that it doesn't have any SQL dependencies and it will run and demonstrate the problem when added to the SampleWebSite? (Feel free to use the existing web service.) A simple sample that demonstrates the problem combined with the proposed fixes above would go a long way to fixing this in the Toolkit. Thanks!
the trouble is in javascript, not in sql server.
this the most simple example:
<%@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="false" %>
<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
headrunat="server"><title>Untitled Page</title></
head><
body><formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><div><cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="MyCategory"LoadingText="wait..."PromptText="select"ServiceMethod="MyMethod"TargetControlID="DropDownList1"ServicePath="MyWebService.asmx"></cc1:CascadingDropDown></div><asp:DropDownListID="DropDownList1"runat="server"></asp:DropDownList><asp:ButtonID="Button1"runat="server"Text="Button"/> </form></
body></
html>
and the code behind:
ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.ClickResponse.Write(
Me.DropDownList1.SelectedItem.Text)EndSubProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.LoadIfNot Page.IsPostBackThenMe.CascadingDropDown1.SelectedValue ="1"EndIfEndSub
use a web service that fill the dropdown with this
value, text
--- --
1, aaaaa
2, bbbbb
3, ccccc
Step by Step:
run this page
look the page and you can see "aaaaa" selected in the dropdown
dont chage the selected item
click the button
response.write will write "undefined"
change the selected item and then click the button
response.write will write the rigth text
what happen??
in java script only verify the selected value. when load the page the dropdown is empty, (dont have any item), but has a selected item, when ajax fill the dropdown then verify if the selected value is change, but the selected value dont change, only has many new items and show the correct text, but the selected value is the same, then javascript dont save or update the client state. and when you click the button you read "undefined" because the text is undefined when the dropdown was empty, but if you change the selected item, then you change the selected value and now java update the client state fine. and finally if you click the button you can read the right text.
Thanks for the demonstration! I've openedwork item 8181 to track this.
No comments:
Post a Comment