lffit
asked on
Unable to reset Ajax Combobox control at runtime
Currently I have two Combobox controls. Both have a static list of selections as follows:
<cc1:ComboBox ID="TypeCB" runat="server" RenderMode="Block">
<asp:ListItem Selected="True" Value="0">--Select--</asp: ListItem>
<asp:ListItem>a</asp:ListI tem>
<asp:ListItem>b</asp:ListI tem>
</cc1:ComboBox>
<cc1:ComboBox ID="SelectCB" runat="server" RenderMode="Block"
AutoPostBack="True" EnableViewState="False">
<asp:ListItem Selected="True" Value="0">--Select--</asp: ListItem>
<asp:ListItem>1</asp:ListI tem>
<asp:ListItem>2</asp:ListI tem>
</cc1:ComboBox>
During runtime, I want both Combobox's to reset their displayed values to "--Select--" whenever the second Combobox "SelectCB" throws a index changed event. I'm using vb .net and I try to change the SelectedIndex or SelectedValue properties but they simply aren't changing from the selected values. Being a relative VB newbie I'm unsure what piece of this I'm missing.
My only real goal is to reset the controls back to their default settings. How can I accomplish this?
<cc1:ComboBox ID="TypeCB" runat="server" RenderMode="Block">
<asp:ListItem Selected="True" Value="0">--Select--</asp:
<asp:ListItem>a</asp:ListI
<asp:ListItem>b</asp:ListI
</cc1:ComboBox>
<cc1:ComboBox ID="SelectCB" runat="server" RenderMode="Block"
AutoPostBack="True" EnableViewState="False">
<asp:ListItem Selected="True" Value="0">--Select--</asp:
<asp:ListItem>1</asp:ListI
<asp:ListItem>2</asp:ListI
</cc1:ComboBox>
During runtime, I want both Combobox's to reset their displayed values to "--Select--" whenever the second Combobox "SelectCB" throws a index changed event. I'm using vb .net and I try to change the SelectedIndex or SelectedValue properties but they simply aren't changing from the selected values. Being a relative VB newbie I'm unsure what piece of this I'm missing.
My only real goal is to reset the controls back to their default settings. How can I accomplish this?
You need to add a javascript function that is called in the onchange event of the first combo box and sets the selected index of the second.
on which event you are trying to change the selected value. try to change the selected value or selected index on prerender event. i think,if you reset in page_load event, may be in combobox selected index changed event will reset to selected value. check it. try to reset at pre render event.
ASKER
I've tried to set the SelectedIndex and SelectedValue in the page_load event, however it did not change the currently selected value on postback. To clarify: The first combobox changed index event is blank. I don't intend that to do anything. The second combobox throws the event which makes one of my update panels show based on the chosen criteria. My problem is the selections won't reset back to their default values when this happens.
Public Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
If Page.IsPostBack Then
TypeCB.SelectedIndex = -1
SelectCB.SelectedIndex = -1
End If
End Sub
ASKER
One more addendum to this. One thing I am noticing is that the SelectedValue or Index are indeed changing the values in the background. However, the displayed values are the problem. It's almost like they're getting "stuck" in there. I have the same problem when I try to dynamically populate the second Combobox from the first with three different sets of data. Sometimes when it changes the currently selected value stays in there and causes the application to throw an error.
what it mean -1??? i think it shoul be 0
If Page.IsPostBack Then
TypeCB.SelectedIndex = 0
SelectCB.SelectedIndex = 0
End If
If Page.IsPostBack Then
TypeCB.SelectedIndex = 0
SelectCB.SelectedIndex = 0
End If
I dont have any .net here to check. my hope is that in page load you are reseting right??. but in changed event again it will set into original value. that means the selected value.
ASKER
Yea -1 and 0 both do the same thing in this case. It's actually setting the index correctly. However the Combobox is still displaying the last selected value.
did you try to set in prerender event
ASKER
I tried that, and again it did set the values but the actual visible state of the Combobox has the last selected value in it. It refuses to revert to it's default selection of "--Select--".
can you tell me, whether you are having event handler for selected index changed event on SelectCB combobox. it you have that, put the breakpoint over there and check it. In this event you put that code. through break point check the value assigned during runtime
ASKER
This is the event handler for the SelectedIndexChange. I checked to make sure the values are getting set to what they're supposed to at runtime and they're indeed getting set. I've also tried adding in SelectedIndex = 0 or the Value = 0 within this event to see if it would reset the control but it only resets the values, not the actual visual state.
Protected Sub SelectCB_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SelectCB.SelectedIndexChanged
ResetUI()
If TypeCB.SelectedValue = "0" Or SelectCB.SelectedValue = "0" Then
'Enter error popup here
Else
If TypeCB.SelectedValue = "Assign" And SelectCB.SelectedValue = "Phone" Then
AssignPhonePanel.Visible = True
ElseIf TypeCB.SelectedValue = "Unassign" And SelectCB.SelectedValue = "Phone" Then
UnassignPhonePanel.Visible = True
ElseIf TypeCB.SelectedValue = "Assign" And SelectCB.SelectedValue = "Line" Then
AssignLinePanel.Visible = True
ElseIf TypeCB.SelectedValue = "Unassign" And SelectCB.SelectedValue = "Line" Then
UnassignLinePanel.Visible = True
Else
'Do nothing
End If
End If
End Sub
ASKER
No one out there has run across this problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.