Hello, I have a webpage with 2 DDL controls. DDL1.SelectedValue = DDL2.DataValueField. Everthing works fine if I have DDL1 AutoPostBack checked. I would like to eliminate the postbacks. Below is my code. I do not know why it doesn't work.
Thanks! Steve
ProtectedSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged
Dim strDataTextFieldAsString
DropDownList2.DataValueField = DropDownList1.SelectedValue
strDataTextField = DropDownList1.SelectedValue
strDataTextField = strDataTextField &"text"
DropDownList2.DataTextField = strDataTextField
EndSub
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"SelectCommand="SELECT * FROM [Futures]"></asp:SqlDataSource>
<asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:ConnectionString %>"SelectCommand="SELECT * FROM [Months]"></asp:SqlDataSource>
<asp:DropDownListID="DropDownList1"runat="server"Style="z-index: 100; left: 342px; position: absolute; top: 86px"DataSourceID="SqlDataSource1"DataTextField="Text"DataValueField="Value"></asp:DropDownList>
<asp:DropDownListID="DropDownList2"runat="server"Style="z-index: 102; left: 616px; position: absolute; top: 86px"DataSourceID="SqlDataSource2"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
</div>
</form></body>
SelectedIndexChanged is a server-side event which occurs only after a postback. If you inserted a breakpoint, you'd find that the program never gets there.
DisturbedBuddha:
SelectedIndexChanged is a server-side event which occurs only after a postback. If you inserted a breakpoint, you'd find that the program never gets there.
So what do I do to fix that?
Thanks Steve
Set AutoPostBack="true" for the dropdownlist and just place the dropdownlist in its own updatepanel to hide the visible refresh.
Hello, I already have my dropdownlist1 in an updatepanel with autopostback="true" and the whole page refreshes. If autopostback="false" nothing happens.
Please look at my code on top again.
Thanks for the help
Steve
No comments:
Post a Comment