I have a dropdownList on my webpage inside update panel. When I select a different value from the drop-down list, nothing happens which means that the "SelectedIndexChanged" event is not firing.
ASPX Code:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<table class="table table-mv-vouchers" style="margin:0px;" cellspacing="0" cellpadding="0">
<caption class="mv-clearfix">
<asp:DropDownList ID="ddlShort" Width="150" runat="server" AutoPostBack="True" ViewStateMode="Enabled" EnableViewState="true" OnSelectedIndexChanged="ddlShort_SelectedIndexChanged">
<asp:ListItem Text="By Estimate" Value="EstimateValue"></asp:ListItem>
<asp:ListItem Text="By Merchant" Value="MerchantName" Selected="True"></asp:ListItem>
<asp:ListItem Text="By Type" Value="MerchantCategory"></asp:ListItem>
<asp:ListItem Text="By Validity" Value="Validity"></asp:ListItem>
</asp:DropDownList>
</caption>
</table>
</ContentTemplate></asp:UpdatePanel>
Server Side Code:
protected void ddlShort_SelectedIndexChanged(object sender, EventArgs e)
{
string ByShort = ddlShort.SelectedValue;
if (ByShort != null)
{
DataSet dsAllMerchant = Main.Instance.serClient.GetMerchantList(null,true, ByShort, null,currentBaID,true);
DataTable newdata = this.GenerateData(dsAllMerchant.Tables[0]);
lvGiftVoucher.DataSource = newdata;
lvGiftVoucher.DataBind();
}
}
My problem was <caption class="mv-clearfix"> </caption> tag, I think this tag is not recognize. After deleting this tag dropdownlist is firing. Thanks all for your answering.
I think you should add a trigger to your UpdatePanel, like that:
<asp:updatepanel ...>
<triggers>
<asp:asyncpostbacktrigger controlid="DrpEmployeeType" eventname="SelectedIndexChanged" />
</triggers>
</asp:updatepanel>
Change UpdatePanel update mode to always
UpdateMode="Always"
Ensure that you have:
a ScriptManager on your page
an UpdatePanel which wraps the lvGiftVoucher markup
provided a unique Id to you update-panel
an AsyncPostbackTrigger for dropdown SelectedIndexChanged event
set UpdateMode to Conditional
AutoPostback = "True" for the dropdwonlist (you already did it)
Dropdown markup (as is, just remove the updatepanel wrap)
<table class="table table-mv-vouchers" style="margin:0px;" cellspacing="0" cellpadding="0">
<caption class="mv-clearfix">
<asp:DropDownList ID="ddlShort" Width="150" runat="server" AutoPostBack="True" ViewStateMode="Enabled" EnableViewState="true" OnSelectedIndexChanged="ddlShort_SelectedIndexChanged">
<asp:ListItem Text="By Estimate" Value="EstimateValue"></asp:ListItem>
<asp:ListItem Text="By Merchant" Value="MerchantName" Selected="True"></asp:ListItem>
<asp:ListItem Text="By Type" Value="MerchantCategory"></asp:ListItem>
<asp:ListItem Text="By Validity" Value="Validity"></asp:ListItem>
</asp:DropDownList>
</caption>
</table>
UpdatePanel mark-up
<asp:UpdatePanel runat="server" id="up1" UpdateMode="Conditional" ChildrenAsTrigger="False">
<Triggers>
<asp:AsyncPostbackTrigger ControlId="ddlShort" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<!-- lvGiftVoucher markup here -->
</ContentTemplate>
</asp:UpdatePanel>
I agree with Sachu.....Server Side Coding, on "PageLoad Event" ....(!IsPostback) Event should happen inside & call "Drop downList"
is your webpage created with master page? If so then check that your form tag is in which page master page/webpage. If it is in master page then simple emit that one and use form tag in webpage.
try the following:
1. add a try-catch block and see if you are getting any exception.
2. if your update panel UpdateMode is conditional, then you have to manually call Update() method or the panel will not update.
The same code is working fine in my PC....
Edited,
try this
add following code inside your Update panel
<Triggers>
<asp:PostBackTrigger ControlID="ddlshort" />
<asp:AsyncPostBackTrigger ControlID="ddlshort" EventName="SelectedIndexChanged" />
</Triggers>
hope this work....
Related
I have an aspx page in which I have Ajax UpdatePanel which has a AJAX Tabcontainer which has 5 tab. In First tab I have a DropDownList for ProductID. In the second tab I have used a UserControl whose parameter needs to be reflected based on productID. I want to Access the DropDownList ProductID in the user control which I am not getting. Part of my code is
DropDownList IDList = (DropDownList)(this.Parent.FindControl("ProductID");
this is not working and I am getting NULL. I also have Tried
DropDownList IDList = (DropDownList)(this.Page.FindControl("ProductID");
Please tell me how I can do this.
As asked Part of necessary code is
<asp:UpdatePanel ID="UpdatePanelTankFormula" runat="server">
<ContentTemplate>
<asp:tabcontainer id="TabContainerTankFormula" AutoPostBack="true" runat="server" OnClientActiveTabChanged="clientActiveTabChanged" activetabindex="0" style="width:100%;">
<asp:TabPanel ID="InputDataTab" runat="server" HeaderText="Data Input">
<ContentTemplate>
<asp:DropDownList id="TankNameCombo" DataTextField="TankName" runat="server" AutoPostBack="true" DataValueField="customertankid" width="200px" onclick="javascript:SetHiddenField();"> </asp:DropDownList>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="LacticAcidAdditionTab" runat="server" HeaderText="Lactic Acid Addition">
<ContentTemplate>
//My user control
<UC:TankNote runat="server" ID="LaticTankNotesUC" GetNoteType="LAC" MEQMode="False"></UC:TankNote>
</ContentTemplate>
</asp:TabPanel>
</asp:tabcontainer>
<ContentTemplate>
</asp:UpdatePanel>
Now in the Code Behind of this User Control I want to access this DropDownList, which I am not getting. For the fix I have define a Public function that return the value of this list. But its a fix not solution.
You will have something like this in tab control.
<cc1:TabContainer ID="TabContainer1" runat="server">
<cc1:TabPanel ID="TabPanel1" runat="server">
<ContentTemplate>
<asp:DropDownList id="dropdownlist1" runat="Server"/>
</ContentTemplate>
</cc1:TabPanel>
So first you need to find tabPanel1 then find dropdownlist1 like following.
TabContainer TabContainer1= (TabContainer)(this.Page.FindControl("TabContainer1");
if (TabContainer1!=null){
TabPanel TabPanel1= (TabPanel)(this.TabContainer1.FindControl("TabPanel1");
if(TabPanel1 !=null){
DropDownList dropdownlist1= (DropDownList)(this.TabPanel1.FindControl("dropdownlist1");
}}
Here is the scenario,
I have one update panel in which I have radio button.
On check of radio button I want to enable Panel which is outside the update panel.
I have tried following 2 things:
Placing the panel in another update panel didn't work.
Using JavaScript on click of radio button didn't work.
placing the panel in another updatepanel and set update mode as conditional.
You need to do one more thing
On check of radio button event you need to call update method of newly added update panel
UpdatePanel1.Update();
I hope this code sample helps you.
<asp:UpdatePanel ID="udp1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:RadioButton ID="rb1" runat="server" AutoPostBack="true" OnCheckedChanged="Control_CheckedChanged"
Text="Text" GroupName="Group1" />
<asp:RadioButton ID="rb2" runat="server" AutoPostBack="true" OnCheckedChanged="Control_CheckedChanged"
Text="Text2" GroupName="Group1" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="udp2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnl1" runat="server" Visible="false">
<asp:Label ID="lblText" runat="server" Text="Text"/>
</asp:Panel>
</ContentTemplate>
<asp:AsyncPostBackTrigger ControlID="rb1" />
<asp:AsyncPostBackTrigger ControlID="rb2" />
</asp:UpdatePanel>
protected void Control_CheckedChanged(object source, EventArgs e)
{
pnl1.Visible=rb1.Checked;
}
Is this a known behavior? and if it is how do I make it work?
I have 2 update panels. Each one has a DropDownList control inside of
it.
I have 1 button that sets-up (binds) the first DropDownList. This
works.
When I change the 1st DropDownList, it should update the 2nd
DropDownList.
For some reason, the 2nd dropdown list never gets updated.
Here is the pseudo--code:
1st Update Panel & DropDownList:
<asp:Button ID="btnSet" runat="server"></asp:Button>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSet" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Code Behind:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
BindSecondDropDownList();
}
Help me figure this one out.
You can merge them all in one updatepanel, dont forget btnSet.OnClick event
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnSet" runat="server"></asp:Button>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
This is called cascading dropdown lists, and there's a known technique for it, and a control provided by ASP.Net Ajax...
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx
I have a radiobuttonlist that is hardcoded into my asp.net page like so:
<asp:RadioButtonList runat="server" ID="rblOrientation" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rblOrientation_onSelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Portrait" Value="P" Selected="True"></asp:ListItem>
<asp:ListItem Text="Landscape" Value="L"></asp:ListItem>
</asp:RadioButtonList>
The code behind is as follows:
protected void rblOrientation_onSelectedIndexChanged(object sender, EventArgs e)
{
ddlPaperSize_onSelectedIndexChanged(sender, e);
}
Basically what happens is it calls on another function which updates a bunch of values that
are within an update panel. This is also hardcoded in and looks like this:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label ID="lblPaperWidth" runat="server" />
<span id="txtUOMWidth" runat="server" /> ×
<asp:Label ID="lblPaperHeight" runat="server" />
<span id="txtUOMHeight" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rblOrientation" />
<asp:AsyncPostBackTrigger ControlID="ddlPaperSize" />
<asp:AsyncPostBackTrigger ControlID="ddlScale" />
</Triggers>
</asp:UpdatePanel>
Everything works fine the first time I change the value of the radiobuttonlist, however, if I try a second time it does not work. Does anyone know why this might be? Any advice would be great, thanks!
note: From the testing I have done, this is the only control where the OnSelectedIndexChanged is not acting how I expected it to. The event for the rest of the controls fires correctly
Try this code, which works fine for me.
<asp:ScriptManager ID="smMain" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" >
<ContentTemplate>
<asp:RadioButtonList runat="server" ID="rblOrientation" RepeatDirection="Horizontal"
OnSelectedIndexChanged="rblOrientation_onSelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Portrait" Value="P" Selected="True"></asp:ListItem>
<asp:ListItem Text="Landscape" Value="L"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
I have two update panels at my ajax page. This is first time I'm using updatepanel and I don't know what is wrong. I think only btnFilter's Click event must trigger the second update panel's content but changing combo values (which also hides/unhides btnFilter button) makes second updatepanel change content (at least I see transferred data with firebug & second updatepanel blinks sometimes). Online here.
<asp:UpdatePanel ID="upComparison" runat="server">
<ContentTemplate>
Brand:
<asp:DropDownList ID="ddlBrands" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlBrands_SelectedIndexChanged"
AppendDataBoundItems="true">
<asp:ListItem Value="" Text="Please select a brand..." />
</asp:DropDownList>
<asp:Panel ID="pModels" runat="server" Visible="false">
Model:
<asp:DropDownList ID="ddlModels" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlModels_SelectedIndexChanged" />
</asp:Panel>
<asp:Panel ID="pButton" runat="server" Visible="false">
<asp:UpdateProgress ID="upMain" runat="server" DisplayAfter="100">
<ProgressTemplate><img src="/Assets/Images/loader.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="btnFilter" runat="server" Text="Filter"
OnClick="btnFilter_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upList" runat="server">
<ContentTemplate>
<asp:Repeater ID="rProducts" runat="server">
<ItemTemplate>some code here</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFilter" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
By default, every UpdatePanel will be refreshed during every asynchronous postback.
To change this behavior, set the UpdateMode property to Conditional.