Fire SelectedIndexChanged event on button click for dropdown - c#

i change dropdown list with button click like this:
ddl.selectedIndex+=1
my ddl has a SelectedIndexChanged event which is not firing if index changed through button. Is it a normal behavior? Should I create separate method and call it right after the ddl.selectedIndex+=1 or there's a better way?

I'm assuming you're using ASP.NET? If so, setting AutoPostBack may help:
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true">
</asp:DropDownList>

Related

how to add textChange Event In autoComplete TextBox

I've problem in my page sample.aspx textbox effected by JavaScript autocomplete
and textbox has event ontextchanged when i select any from autocomplete result the event doesn't work,
ex: google search when select from autocomplete result it do event.
<asp:TextBox ID="CUSMO1"
AutoPostBack="True"
runat="server"
Height="25px" Width="280px"
ontextchanged="CUSMO1_TextChanged"
AutoCompleteType="Enabled" >
</asp:TextBox>
How to Resolve?
Did you checked ontextchanged event with autocomplete off?

LinkButton fire OnClick Event and Javascript event

I have the following code which executes the C# onclick event.
<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click1">Apply Filter</asp:LinkButton>
I would also like to add a javascript onclick event to happen following this of
setVisible('cfilterpopup');
Basically I need it to store some information from the page when LinkButton4_Click1 happens and then setVisible sets an area of my page back to hidden because they entered that information and don't need to see it again.
What is the correct syntax to get both the C# onclick and the javascript onclick together. I'm looking for something like this but I know this is wrong
<asp:LinkButton ID="LinkButton4" runat="server" onclick="LinkButton4_Click1;setVisible('cfilterpopup')">Apply Filter</asp:LinkButton>
you need to use onclient click
<asp:Button OnClientClick="String" />
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx

How do I add an UpdatePanel and its trigger programmatically?

I'm adding a variable number of update panels in Page_Init.
I already have a script manager in my master page.
The problem is that when I try to add a trigger like:
AsyncPostBackTrigger trig2 = new AsyncPostBackTrigger();
trig2.ControlID = ddl22.UniqueID;
trig2.EventName = "SelectedIndexChanged";
up2.Triggers.Add(trig2);
where ddl22 is a DropDownList, the event never seems to trigger the UpdatePanel.
In the UpdatePanel I have another DropDownList the data of which i want to change when the trigger happens.
The funny thing is that in the master page I have a timer. This timer is only supposed to trigger the UpdatePanel in the master but it seems to trigger all of my update panels. However, even when it triggers the update panel in the child page, the second DropDownList does not change its data.
The data is databound to the DropDownList in the UpdatePanel in page_init. It is bound to an objectdatasource which uses the selected item in the first DropDownList as a parameter to determine what data it should bind.
Did you set AutoPostBack="True" for your drop down list? I suspect this is the issue.
Also set your update panel mode to conditional-UpdateMode="Conditional" so that i does not affect other update panels.
Try this,
In Source Code,
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl1_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddl2_SelectedIndexChanged"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="ddl2" />
</Triggers>
</asp:UpdatePanel>
You can manually call the UpdatePanel to refresh without specifying a trigger on a postBack event. Firstly, set the UpdateMode property to 'Conditional', then you can just call an update on your updatepanel from code behind like
MyUpdatePanel.Update();

About SelectedIndex property in a DropDownList

Sorry for my ignorance, but I've always believed that setting the SelectedIndex property of a DropDownList the SelectedIndexChanged event is fired... Am I wrong?
Searching in the documentation I haven't found anything clear...
Thanks
No it cannot fire the selectionchange event.
if you are settting programatically than it not fire the selectionchange event.
DropDownlist Class Selected Index Changed Event fires when the selection from the list control changes between posts to the server.
Please make sure about following to fire the event.
AutoPostBack="true" How to use DropDownList AutoPostBack feature
onselectedindexchanged="Name of the Handler"
Below is the code.
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true"
onselectedindexchanged="ddl1_SelectedIndexChanged">
<asp:ListItem Text ="1" Value="1"></asp:ListItem>
<asp:ListItem Text ="2" Value="2"></asp:ListItem>
</asp:DropDownList>
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
Note - On setting the index at runtime will never fire the event.
Please go through the following links as well.
How to: Respond to Changes in List Web Server Controls
How to use DropDownList AutoPostBack feature

RadioButtonList OnSelectedIndexChanged

I'm looking for the best way to handle a change of index being selected on a ASP.net RadioButtonList (C# code behind). I have 3 list items. For the first one, I want it to show a hidden asp:textbox on the page, whereas the other 2 will hide the textbox.
//asp.net side
<asp:RadioButtonList ID="_indicatorAckType" runat="server" RepeatDirection="Horizontal"
enabled="true" OnSelectedIndexChanged="onAckTypeChanged">
<asp:ListItem Text="None" />
<asp:ListItem Text="SHOW" />
<asp:ListItem Text="HIDE" />
</asp:RadioButtonList>
//code behind
protected void onAckTypeChanged(object sender, EventArgs e)
{
if (_indicatorAckType.SelectedItem.Text == "SHOW")
_myTextboxID.Visible = true;
else
_myTextboxID.Visible = false;
}
I initially tried using onclick event handlers, but I've been told that ListItem's cannot use onclick events with radio button items. What am I doing wrong here? This does not throw any errors or have any visibly obvious problems. I have tried making onSelectedIndexChanged do nothing except show the textbox and that doesn't work either.
Any help is appreciated! Thanks everyone.
On the RadioButtonList, set the AutoPostBack attribute to true.
Have a look at this it might help. And I suggest to turn off autopostback if enabled on radio button do it all on client side using jquery.
example:
Using jQuery, hide a textbox if a radio button is selected

Categories

Resources