update panel - dropdown selected index change event not triggering - c#

I have one dropdownlist on my page (.aspx) and based on change of selected value i need to bind the data to checkboxlist control which is on the same page. To avoid entire page to be refreshed, i have put the controls in the update panel.
But when i am changes the selection from the dropdown,, it is getting back to the first value itself and the selected index changed even is not getting triggered.
here is how I have put my controls in the update panel.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<div id="attachmentdiv">
<asp:DropDownList ID="ddlimportfiles" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlimportfiles_onselectedindexChange"></asp:DropDownList>
</div>
<div id="voltagediv">
<asp:CheckBoxList ID="chkBoxLstVoltage" runat="server"></asp:CheckBoxList>
</div>
<asp:Button ID="btnGenerateZBF" runat="server" Text="Generate ZBF" OnClick="GenerateZBF_Click" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlimportfiles" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
kindly suggest what I am doing wrong here.

Related

Ajax Tab Container loads the first tab always when fire an event

I have an AJAX tab container that contains two tab panels.
The problem when I fire an event on the second tab it reloads the first tab.
Any help? Suggestions? below is a sample of the aspx code
<AJAX:TabContainer runat="server" ID="tcMain" ActiveTabIndex="0">
<AJAX:TabPanel runat="server" ID="tpTab1" TabIndex="1">
<HeaderTemplate>
Tab1
</HeaderTemplate>
<ContentTemplate>
<div runat="server" id="div1">
<asp:UpdatePanel ID="upTab1" runat="server">
<ContentTemplate>
//entry and events
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</AJAX:TabPanel>
<AJAX:TabPanel runat="server" ID="tpTab2" TabIndex="2">
<HeaderTemplate>
Tab2
</HeaderTemplate>
<ContentTemplate>
<div runat="server" id="div2">
<asp:UpdatePanel ID="upTab2" runat="server">
<ContentTemplate>
// entry and events
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</AJAX:TabPanel>
</AJAX:TabContainer>
Most likely this is because of page post-back happening.you can manage the data using ViewState property this link may solve your issue HElP
.

How to prevent UpdatePanel from resetting values outside the panel?

Here is my problem :
I select a type using ddlType
I click on btnAddChoice to add a few choices
I click on btnSubmit to save the form
But when I try to get ddlType.SelectedValue in btnSubmit_Click(), it's always back to "Select a type".
If I don't do step #2 then it works fine.
From what I understand, the problem is related the ajax call (postback) and could be solved by saving the SelectedValue in the Session or ViewState.
But I have many many other controls (such as ddlType) on this page so it does not seem like an elegant solution. I was hoping for the framework to keep the selected values in the ViewState automatically ... Any idea ? After all, is it not the goal of UpdatePanel to update just the panel ?
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="ddlType" runat="server">
<asp:ListItem Text="Select a type" Value=""></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="Two" Value="2"></asp:ListItem>
<asp:ListItem Text="Three" Value="3"></asp:ListItem>
</asp:DropDownList>
<div>
<strong>Choices</strong>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddChoice" EventName="Click" />
</Triggers>
<ContentTemplate>
<ul class="list-unstyled">
<asp:PlaceHolder runat="server" ID="phChoices"></asp:PlaceHolder>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnAddChoice" runat="server" Text="Add Choice" CausesValidation="false"
OnClick="btnAddChoice_Click" />
</div>
<asp:Button ID="btnSubmit" runat="server" Text="Add question"
OnClick="btnSubmit_Click" />
UPDATE
Part of the problem was caused by :
$('#<%= MainPanel.FindControl("btnAddChoice").ClientID %>').click(function () {
var ddlType = $('#<%= MainPanel.FindControl("ddlType").ClientID %>');
ddlType.attr('disabled', 'disabled');
});
Please see this question for details.
Regarding other controls also empty, the reason is that "dynamically created controls have to be created each and every post-back"
Try adding something like this to your ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
Then all the code which you want to get refreshed will come under Update Panel
<asp:Updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
...All your HTML content here
</ContentTemplate>
</asp:Updatepanel>
Hope that helps
More information on EnablePartialRendering
UPDATE
Also if your dropdownlist value is not getting saved because of Updatepanel
try Request.Form and check
Request.Form.Get("dropdownlistID").ToString());

button click event on update panel not firing in multiple user control

I am having an update panel which user control in it
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:SelectionAjax ID="SelectionAjax1" runat="server" />
<ppmp:PinPadModal ID="ppmodal" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
and inside this user control I am calling another two user controls each user control which has its own update panel
// First User Control
<asp:UpdatePanel ID="UpP1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFinalConfirmation" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnFinalConfirmation" runat="server" Text="Confirm" OnClick="btnFinalConfirmation_Click1" />
</ContentTemplate>
</asp:UpdatePanel>
//Second User Control
<asp:UpdatePanel ID="UpPanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnConfirmation" runat="server" Text="Confirm" OnClick="btnConfirmation_Click1" />
</ContentTemplate>
</asp:UpdatePanel>
The issue is that button click event is only being fired on the second user control not the first one how should I solve this
Include ScriptManager in your Aspx Page.This ScriptManager control provides support for client-side AJAX features in an AJAX enabled web pages.
<asp:ScriptManager ID="ScriptManager1" runat="server"/>

ASP.NET Update Panel within ListView Control not updating

Basically I have this situation
Page >
Update Panel >
User Control >
List View >
User Control (Within item template) >
Update Panel
When I click on a button within the inner most update panel, I want the content of the update panel to update. This isn't happening. However, the click handler is being hit fine asynchronously. The update panel just doesn't want to update.
Code - I've created a simple test web app that replicates the problem, and shared it on my google drive: UpdatePanelInListViewTest.zip, but here's the markup:
Page:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="ajaxParent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:ListUserControl ID="ListUserControl1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
List User Control:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="ListUserControl.ascx.cs" Inherits="UpdatePanelInListViewTest.ListUserControl" %>
<%# Register src="MiniWidget.ascx" tagname="MiniWidget" tagprefix="uc1" %>
<asp:ListView ID="lstTest" runat="server">
<ItemTemplate>
Item
<uc1:MiniWidget ID="MiniWidget1" runat="server" />
</ItemTemplate>
</asp:ListView>
Mini Widget User Control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MiniWidget.ascx.cs" Inherits="UpdatePanelInListViewTest.MiniWidget" %>
<asp:UpdatePanel ID="ajaxWidget" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LinkButton ID="lnkTest" runat="server" onclick="lnkTest_Click">Test</asp:LinkButton>
<asp:Label ID="lblTest" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
I've tried different permutations of this; i.e. having the button outside the panel and adding a trigger etc but I just cannot get it to update.
It appears that because the user control is within an item template of the parent list view it causes the update panel to not update for some reason...
The problem is to do with when you call the databind method within ListUserControl.
Moving lstTest.DataBind(); so that it executes within the Page_Load rather than the Page_PreRender fixes the issue for your simple test web app.
have u tried:
<asp:UpdatePanel ID="ajaxPanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnTest" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="btnTest" runat="server" Text="Test" onclick="btnTest_Click" />
</ContentTemplate>
</asp:UpdatePanel>

Label in Update panel does not refreshing

I have a Update panel in Master page, and have a label and button in the content page,, when i click on the button and assign some text to label , the value set to label does not reflect, i think the issue due to update panel in Master page, can anyone help?
In Master Page
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
In Content Page
I solve my Problem, I am posting here may be it will help someone
Add the asp:PostBackTrigger in update panel
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="ContentPlaceHolder1" />
</Triggers>
</asp:UpdatePanel>

Categories

Resources