Avatar of lffit
lffit
Flag for United States of America 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:ListItem>
                            <asp:ListItem>b</asp:ListItem>
                        </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:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                        </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?
.NET ProgrammingASPAJAX

Avatar of undefined
Last Comment
lffit

8/22/2022 - Mon
strickdd

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.

sksJegadeesh

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.
lffit

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

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
lffit

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.
sksJegadeesh

what it mean -1??? i think it shoul be 0

 If Page.IsPostBack Then
            TypeCB.SelectedIndex = 0
            SelectCB.SelectedIndex = 0
        End If
sksJegadeesh

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lffit

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.
sksJegadeesh

did you try to set in prerender event

lffit

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--".
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
sksJegadeesh

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
lffit

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

Open in new window

lffit

ASKER
No one out there has run across this problem?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
lffit

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.