RadioButtonList set to AutoPostBack = true but still not firing OnSelectedIndexChanged - c#

I have 2 RadioButtonLists and I want only one option to be selected, f.i. if you select an option in List 1 the selection in List 2 should be cleared.
AutoPostBack and EnableViewState is set to true, but still the Method never fires. I have also checked if the Index actually changes, it does. I think that the PostBack just doesn't occur, but I don'T know why.
I'm thankful for any help.
ascx:
<asp:RadioButtonList ID="_listOne" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButtonList>
<asp:RadioButtonList ID="_listTwo" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButtonList>
Code Behind:
protected void ListOneIndexChanged(object sender, EventArgs e)
{
_listTwo.ClearSelection();
}
protected void ListTwoIndexChanged(object sender, EventArgs e)
{
_listOne.ClearSelection();
}

change the control to RadioButton and add GroupName to them will do the trick:
<asp:RadioButton ID="_listOne" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListOneIndexChanged">
</asp:RadioButton>
<asp:RadioButton ID="_listTwo" runat="server" GroupName="xx" AutoPostBack="true" OnSelectedIndexChanged="ListTwoIndexChanged">
</asp:RadioButton>

try to use just one radibuttonlist and options.
<asp:RadioButtonList id="radiolist1" runat="server" OnSelectedIndexChanged="ListOneIndexChanged">
<asp:ListItem selected="true">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:RadioButtonList>

Related

How to prevent one update panel from affecting another c# asp

My problem is the following, when I first use the droplist of the first updatepanel to function correctly it shows me the label and textbox that are hidden, everything works fine.
But, when I use first the dropProvince, canton or district, they implement the method
protected void
droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged (object sender, EventArgs and )
{
MessageBox.Show ("hello");
this.datosPropietarioLblNumIdentificacion.Visible = true;
this.datosPropietariotxtNumIdentificacion.Visible = true;
}
each drop has its own method
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.datosPropietarioLblNumIdentificacion.Visible = false;
this.datosPropietariotxtNumIdentificacion.Visible = false;
}
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" Text="Tipo de Identificación"></asp:Label>
<asp:DropDownList ID="droplistTipoIdentificacionDatosPropietario"
runat="server"
Width="100%"
Height="30px"
AutoPostBack="true"
OnSelectedIndexChanged="droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged">
<asp:ListItem Text="Cédula Identidad" Value="C"></asp:ListItem>
<asp:ListItem Text="Cédula de Residencia" Value="R"></asp:ListItem>
<asp:ListItem Text="Cédula Jurídica" Value="J"></asp:ListItem>
<asp:ListItem Text="Pasaporte" Value="P"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind call
protected void droplistTipoIdentificacionDatosPropietario_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("hola");
this.datosPropietarioLblNumIdentificacion.Visible = true;
this.datosPropietariotxtNumIdentificacion.Visible = true;
}
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="grid3">
<asp:Label runat="server" Text="Provincia"></asp:Label>
<asp:DropDownList ID="droplistProvincia"
AutoPostBack="true" onchange="testProvincia"
OnSelectedIndexChanged="droplistProvincia_SelectedIndexChanged"
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" Text="Cantón"></asp:Label>
<asp:DropDownList ID="droplistCanton" CssClass="item15"
AutoPostBack="true"
OnSelectedIndexChanged="droplistCanton_SelectedIndexChanged"
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" CssClass="item16" Text="Distrito"></asp:Label>
<asp:DropDownList ID="droplistDistrito"
AutoPostBack="true"
OnSelectedIndexChanged="droplistDistrito_SelectedIndexChanged"
CssClass="item17" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
You might have a copy/paste issue; sometimes copy/paste will not execute code. Try deleting the code-behind methods from each dropdown and re-adding them.
<asp:DropDownList ID="droplistProvincia"
AutoPostBack="true" onchange="testProvincia"
OnSelectedIndexChanged="droplistProvincia_SelectedIndexChanged" <- delete this
Width="100%" runat="server" Height="30px">
<asp:ListItem Text="Seleccione"></asp:ListItem>
</asp:DropDownList>
Delete the line as shown above, and also delete the code-behind. Re-add by double-clicking the dropdown list.
Hope that helps. It's hard to tell what the problem is from your question.

How to find the data which relatd to dropdown selected value asp.net

I want to fil the book ISBN on text box which matched with the Title selected on Dropdown menu. Please advice me how to proceed me ...
First of all you need to change your mark-up like this:-
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" AppendDataBoundItems="true"
DataSourceID="SqlDataSource1" DataTextField="Book_Title"
DataValueField="isbn" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Select Book" Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Knowledge_CenterConnectionString %>"
SelectCommand="select Book_Title,isbn from Title"></asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="ISBN"></asp:Label>
<asp:TextBox ID="txtISBN" runat="server"></asp:TextBox>
Then simply on dropdownlist selected index change event bind the value to textbox:-
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
txtISBN.Text = DropDownList1.SelectedValue;
}

asp.net drop downlist value reset on button click within jquery dialog

I have a div , within which I have a button and an asp.net dropdownlist. I can change the value in the dropdownlist . But as soon as the button is clicked the value in the drop down list is again set to the default initial value. Is there a way I can solve this problem ? I do not want the dropdownlist to go back to its initial value.
aspx
<div id='one'>
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
<asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click"/>
<asp:Label ID="Label2" runat="server" Text="Set The Alert Email Interval to every :" CssClass="label"
ForeColor="Black"></asp:Label>&nbsp&nbsp&nbsp
<asp:DropDownList ID="ddlTimeInterval" runat="server" >
<asp:ListItem Text="15MIN" Value="15"></asp:ListItem>
<asp:ListItem Text="30MIN" Value="30"></asp:ListItem>
<asp:ListItem Text="1Hr" Value="60"></asp:ListItem>
<asp:ListItem Text="2Hrs" Value="120"></asp:ListItem>
<asp:ListItem Text="8Hrs" Value="480"></asp:ListItem>
<asp:ListItem Text="24Hrs" Value="1440"></asp:ListItem>
<asp:ListItem Text="48Hrs" Value="2880"></asp:ListItem>
</asp:DropDownList>
<br />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
javascript
function ViewModelPopup2() {
$("#ViewModalPopupDiv2").dialog({
scrollable: true,
width: 800,
modal: true
});
}
ASPX.CS
protected void btnSendAlertEmail_Click(object sender, EventArgs e)
{
// Code to send email
}
protected void btnConfigureAlerts_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript
(this, this.GetType(), "callScriptFunction", "ViewModelPopup2();", true);
}
}
The problem i can see is that , JQuery and Update Panel. These two never works together properly. You need to remove either. But there is a work around. Check out this one.http://www.codeproject.com/Articles/601683/Working-with-jQuery-within-the-ASP-NET-UpdatePanel

Multiple dropdownlist

i have 4 dropdownlist. when i change the 1st dropdown, onselectindexchanged i need to change all the remaining dropdown values.
I am working on it but i could change only the corresponding or next dropdown value on onselectindexchanged. Please provide me any example or guide me to any good link.
Pls help.. Thanks in advance.
You need to set AutoPostBack of all dropdowns to true and need to add SelectedIndexChanged event for first three drop downs. On SelectedIndexChanged of first dropdown you need to set selected value of second and it will fire SelectedIndexChanged of second and there you will have code to set selected index of third and similarly you will do on wards.
In Html
<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist1_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist2_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist3" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist3_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="dropdownlist4" runat="server" AutoPostBack="true" >
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
1
2
In code behind
protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
dropdownlist2.SelectedIndex = someIndexValue;
}
protected void dropdownlist2_SelectedIndexChanged(object sender, EventArgs e)
{
dropdownlist3.SelectedIndex = someIndexValue;
}
protected void dropdownlist3_SelectedIndexChanged(object sender, EventArgs e)
{
dropdownlist4.SelectedIndex = someIndexValue;
}

Dropdown box chained filters not working?

I am trying to implement a simple filter from one dropdown box to another.
The second dropdown box deos not populate (with any item) when I select an item from the first dropdown.
I am not sure what I am missing.
Please advise.
Here is the ascx code:
<div id="SubmitSection" style="width:auto; height:auto;" class="SubmitSectionStyle">
<div id="DropdownSection" style="text-align:center;">
<asp:DropDownList ID="DropDown1" runat="server" AppendDataBoundItems="true"
onselectedindexchanged="Type_SelectedIndexChanged" ToolTip="Select Category">
<asp:ListItem Text="--Select Category--" Value="" />
<asp:ListItem Value="1">Department</asp:ListItem>
<asp:ListItem Value="2">Safety</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDown2" runat="server">
<asp:ListItem Text="--Select One--" Value="" />
</asp:DropDownList>
</div>
And here is my code behind:
protected void Type_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDown1.SelectedValue == "1")
{
DropDown2.Items.Clear();
DropDown2.Items.Add("DeptTest");
DropDown2.DataBind();
}
else if (DropDown1.SelectedValue == "2")
{
DropDown2.Items.Clear();
DropDown2.Items.Add("SafetyTest");
DropDown2.DataBind();
}
}
In your first dropdownlist, set AutoPostBack="True"
AutoPostBack = "true" // AutoPostBack attribute is missing in DropDown1 due to which the event does not fire
// change your dropdown1 code as
<asp:DropDownList ID="DropDown1" AutoPostBack = "true" runat="server" AppendDataBoundItems="true"
onselectedindexchanged="Type_SelectedIndexChanged" ToolTip="Select Category">
<asp:ListItem Text="--Select Category--" Value="" />
<asp:ListItem Value="1">Department</asp:ListItem>
<asp:ListItem Value="2">Safety</asp:ListItem>
</asp:DropDownList>
You need to set auto postback to true if you want it to update the page on item change.
<asp:DropDownList ID="DropDown1" AutoPostBack="True" runat="server" AppendDataBoundItems="true" onselectedindexchanged="Type_SelectedIndexChanged" ToolTip="Select Category" >
<asp:ListItem Text="--Select Category--" Value="" />
<asp:ListItem Value="1">Department</asp:ListItem>
<asp:ListItem Value="2">Safety</asp:ListItem>
</asp:DropDownList>
You might also want to consider wrapping both these DropDownList controls in an update panel, so that you don't refresh the whole page every time a user changes a selection.

Categories