Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Drop down does not respond to the change event View modes: 
User avatar
Member
Member
christer.anttila-ergoconsulting.com - 12/4/2012 9:56:07 PM
   
Drop down does not respond to the change event
I have created a custom web part called test and added a drop down to the test.ascx file like this:
<asp:DropDownList ID="drpClass" runat="server" OnSelectedIndexChanged="drpClass_Change" />

I have also tried to do it this way:
<cms:LocalizedDropDownList ID="drpClass" runat="server" />

In the test.ascx file I also have the following code:
<cms:LocalizedButton ID="btnOK" Text="Rename Class" runat="server" CssClass="SubmitButton" OnClick="btnOK_Click" EnableViewState="false" />

In the test.ascx.cs file I have the following code:
protected void btnOK_Click(object sender, EventArgs e)
{
int classID = int.Parse(drpClass.SelectedValue);
}

there are four values in the drop down box 1,2,3 and 4.

When I run this in debug mode the value of classID always become the first value of the drop down box (1) even if I have picked a different value (2,3 or 4).

Is there any additional code I need to add to my web part to enable the change even for the drop down control?

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 12/5/2012 6:21:20 AM
   
RE:Drop down does not respond to the change event
The AutoPostback property of the DDL to true.

User avatar
Member
Member
christer.anttila-ergoconsulting.com - 12/5/2012 4:50:58 PM
   
RE:Drop down does not respond to the change event
FroggEye,

Thanks for your suggestion, however I still experience the same issue.

In the code below the drpClass.SelectedIndex returns 0 which is the first item in the ddl even if I select the 2nd, 3rd or 4th item.
protected void drpClass_Change(object sender, EventArgs e)
{
txtNewClassName.Text = drpClass.SelectedIndex.ToString();
}

The difference with AutoPostBack="true" set on the ddl is as expected that I get a postback as soon as I select something in the ddl but as explained above I still get the same result.

Any other suggestions as to why this is?

User avatar
Kentico Support
Kentico Support
kentico_janh - 12/6/2012 1:39:05 AM
   
RE:Drop down does not respond to the change event
Hello,

Please define your dropdownlist as the one below:

<asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" AppendDataBoundItems="true" /> 


Best regards,
Jan Hermann

User avatar
Member
Member
christer.anttila-ergoconsulting.com - 12/6/2012 4:24:48 PM
   
RE:Drop down does not respond to the change event
kentico_janh,

Unfortunately this did not fix the issue, drpClass.SelectedValue in drpClass_Change is still the first value in the drop down even if I pick any of the other items.

Do I need any additional code in the cs file to allow the drop down to send the selected value instead of the first value?

User avatar
Member
Member
christer.anttila-ergoconsulting.com - 12/6/2012 10:14:38 PM
   
RE:Drop down does not respond to the change event
For anyone battling this same issue the fix is simple.

Just add a check for if you are dealing with the initial page hit or a postback. Otherwise the drop down rebound each time and the SelectedValue will be the default value.

if (!IsPostback)
{
PopulateDropDown()
}