Example:
<asp:DropDownList runat="server" AutoPostBack="true" ID="ddlSample">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
Now if change the item in the above dropdown it will cause all the other dropdowns postback events to fire.
Like
<asp:DropDownList EnableViewState="true" ID="ddlNewSelec" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="ddlNewSelec_SelectedIndexChanged">
<asp:ListItem Text="--Select Test Type--" Value="" />
</asp:DropDownList>
Details:
The Page has ViewState disabled. I try enabling viewstate for the individual dropdowns but it does not matter.
Any idea why this is happeing.
Let me know if you need any more details
EDIT:
The dropdown fires the selectedindexchanged event of all other dropdowns on the form. The dropdown named as ddlSample is doing nothing just causing postback but why the selectedindexchanged evenet of other dropdowns fired up.
Additional Info:
All the inputs are in updatePanel and removing them does not make any effect.
In Page Load i am not doing anything on postback
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSomeDDLs();
}
}
You didn't bind the SelectedIndexChanged event on the "ddlSample" dropdown. Please try binding that property like so..
<asp:DropDownList ID="ddlSample" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSample_SelectedIndexChanged">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
The answer seems to be very weird but this is true.
This is happening just because of EnableViewState property set to false.
Related
i'm making a .aspx page with a checkbox that when it was checked it have to change the visibility of a radio list.
When i check it, the radio list was shown but when i uncheck it, the radio list don't disappears.
So, my code is that:
Front-end:
<asp:CheckBox ID="ckbProspect" runat="server" AutoPostBack="true"
oncheckedchanged="ckbProspect_CheckedChanged" />
<asp:RadioButtonList ID="rbListProspect" runat="server" Visible="false"
AutoPostBack="true" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Sim"></asp:ListItem>
<asp:ListItem Value="0" Text="Não"></asp:ListItem>
</asp:RadioButtonList>
Back-end
protected void ckbProspect_CheckedChanged(object sender, EventArgs e)
{
rbListProspect.Visible = ckbProspect.Checked;
}
How can i fix that and what it's wrong?
Try this:
<asp:CheckBox ID="ckbProspect" runat="server" Checked="false"
OnCheckedChanged="ckbProspect_CheckedChanged" AutoPostBack="true"/>
P.S: I believe there's nothing wrong with your code, it's working just fine.
I've 2 radio buttons in a user control and control is registered to the page. When i click on the radio button, the event(CheckChanged) is not firing.
<asp:View ID="viewfirst" runat="server">
<asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:RadioButton ID="radio1" Text="Yes" Enabled="true" runat="server" />
<asp:RadioButton ID="radio2" Text="No" Enabled="true" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:View>
Below is code in behind file of the control.
Protected Sub radio1_CheckedChanged(sender As Object, e As EventArgs) Handles radio1.CheckedChanged
//
//
End Sub
It seems everything looks good, but something is wrong. Can you please let me know.
Set autopostback=true for checkbox - This will trigger the event
UpdateMode=conditional and ChildrenAsTriggers=false for the UpdatePanel - so when you trigger checkbox, it won't trigger full postback
You have to set the event handler of each radio button to OnCheckChanged and put them in the same RadioGroup (GroupName) so they do not fire together. Remember to set AutoPostBack = true for each radio button. Set only one radioButton as checked = true. I can see your code has both checked. Something like this...
The aspx page:
<asp:RadioButton id="radioButton1" runat="server" GroupName="btnGrp" Text="Button 1" AutoPostBack="true" Checked="true" OnCheckedChanged="radioButton1_CheckedChanged"></asp:RadioButton>
<asp:RadioButton id="radioButton2" runat="server" GroupName="btnGrp" Text="Button 2" AutoPostBack="true" OnCheckedChanged="radioButton2_CheckedChanged"></asp:RadioButton>
The code-behind (aspx.cs) page:
protected void radioButton1_CheckedChanged(object sender, EventArgs e)
{
// Your code here
}
protected void radioButton2_CheckedChanged(object sender, EventArgs e)
{
// Your code here
}
Hope this helps!
I am annoyed with a problem I have repeater control in updatepanel like this.
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The problem I face that whenever I select any value from dropdown all the page gets refreshed After spending hours on the google I found a solution i.e, on itemdatabound event of repeater we just need to add the following code after finding the dropdown,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
It worked very well for the dropdown but same is not working for checkboxlist like using the scripmanager instance if I write sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits), it is not working :(
Add ClientIDMode="AutoID" to the Repeater control.
You should not have to add any triggers and you should not even have to call RegisterAsyncPostBackControl. The ChildrenAsTriggers should take care of that.
on Repeater ItemDataBound event
use screiptmanager method RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" put here your checkbox ID "));
Add this Before start of <ContentTemplate>:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="objDropdownlist" EventName="OnSelectedIndexChanged" />
</Triggers>
I have a RadioButtonList with some fixed element and a default selected. If I uncheck the selection with javascript, on postback the SelectedIndexChanged event is not fired.
I would expect that the SelectedIndexChanged is called because the index is changed to -1.
this is the Asp.Net code
<asp:RadioButtonList ClientIDMode="Static" ID="RadioButtonList1" runat="server"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
</asp:RadioButtonList>
and the jquery code
$('#RadioButtonList1 :radio:visible').attr('checked', false);
As far as I know, the stage of data collection from the submit of the form is handled by IPostBackDataHandler.LoadPostData method.
I derived a class from RadioButtonList to verify when LoadPostData is called and I noticed that when non of the radio button is selected the method is not called and the same for SelectedIndexChanged event.
it seems that if the key of RadioButtonList is not present in the Page.Request.Form.Keys array, the LoadPostData is not called.
Any help appreciated.
Try setting AutoPostBack="true"
Example:
<asp:RadioButtonList ClientIDMode="Static" ID="RadioButtonList1" runat="server"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
</asp:RadioButtonList>
According to MSDN's documentation:
Gets or sets a value indicating
whether a postback to the server
automatically occurs when the user
changes the list selection. (Inherited
from ListControl.)
I have checkbox in the DataList. Now I need to execute a code-behind when the checkbox is ticked. As far as I know the itemcommand in datalist will not triggered when the checkbox is ticked. I even tried to put the onCheckChanged event in the checkbox but it even worse the situation (not just does not trigger the event but also does allow me to tick the checkbox at all).
Does anyone has a solution?
thanks
I just created a DataList with a CheckBox in it like this:
<asp:DataList ID="Datalist1" runat="server" DataSourceID="Sqldatasource1">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" Text="text" runat="server" OnCheckedChanged="Checkbox1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:DataList>
and this code-behind
protected void Checkbox1_CheckedChanged(object sender, EventArgs e)
{
}
That allowed me to break into the CheckedChanged event without any problem.
Are you setting AutoPostBack="true" on the <asp:CheckBox control? It might fire the ItemCOmmand event, otherwise, you would have to tap into the CheckChanged event for the control on ItemCreated event.