I have an Ajax update panel inside a nested listview as shown below.
<%# Page Title="LV Ajax" Language="VB" MasterPageFile="~/MasterPages/SimpleMasterPage.master"
AutoEventWireup="false" CodeFile="LV Ajax.aspx.vb" Inherits="LV_Ajax" %>
ListView Ajax
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ListView ID="OuterListView" runat="server" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
No Data Available.
</EmptyDataTemplate>
<ItemTemplate>
<asp:Label ID="PhotoAlbumIdLabel" runat="server" Text='<%# Eval("PhotoAlbumId") %>'
Visible="false" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="InnerListView" runat="server" DataSourceID="SqlDataSource2">
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<ItemTemplate>
<br />
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' ToolTip='<%# Eval("ToolTip") %>'
Width="400px" Height="300px" />
<br />
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<asp:DataPager ID="DataPager1" runat="server" PageSize="1">
<Fields>
<asp:NextPreviousPagerField FirstPageText="<<" ShowFirstPageButton="True" ShowNextPageButton="False"
PreviousPageText="< " ShowPreviousPageButton="True" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField LastPageText=">>" ShowLastPageButton="True" NextPageText=" >"
ShowNextPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</span>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RenaissanceConnectionString1 %>"
SelectCommand="SELECT [ToolTip], [ImageUrl], [Description], [PhotoAlbumId], [SortOrder] FROM [Picture] WHERE ([PhotoAlbumId] = #PAId) ORDER BY [SortOrder]">
<SelectParameters>
<asp:ControlParameter ControlID="PhotoAlbumIdLabel" DefaultValue="0" Name="PAId"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
</span>
</ItemTemplate>
</asp:ListView>
Unfortunately when I click the datapager buttons although the picture changes correctly, the browser displays the page from the top. If I remove the outer listview it works perfectly keeping its position on the page.
This was working correctly, so if you think the code is correct maybe you could suggest some other changes.
If there is any genius out there who can suggest a solution it would be appreciated.
Many thanks in anticipation.
Maybe if you add ChildrenAsTriggers="true and set UpdateMode to Conditional it will work for you.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
Your <ASP:UpdatePanel> tag is missing its <Triggers> element.
I think that it should be something like
<asp:UpdatePanel ... >
<Triggers>
<AsyncPostBackTrigger ControlID='DataPager1'>
</Triggers>
<ContentTemplate> .....
Related
I have an update panel that includes a gridview with two buttons and a modal popup. When the user clicks btnView, the modal popup appears displaying the relevant information.
My issue is that I have been trying to get the updateprogress to appear during the partial postback and so far have not managed it. I should mention that the same UpdateProgress code does work in a test page that just comprises of a button with a sleep function in the code behind. Here is the html:
<!-- Placing the GridView in UpdatePanel-->
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gv" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataKeyNames="GroupID" GridLines="Both"
BorderWidth="1px" CellPadding="2" ForeColor="Black" OnRowDataBound="gv_RowDataBound" BorderStyle="Double" HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center" AllowSorting="True" CssClass="gvformat">
<AlternatingRowStyle BackColor="#95B9B9" />
<HeaderStyle BorderStyle="Double" BorderColor="Black"/>
<Columns>
<asp:BoundField DataField="FinancialYear" HeaderText="Financial Year" ItemStyle-HorizontalAlign="Center"/>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnView" runat="server" Text="view" OnClick="btnComments_Click" CausesValidation="false" Font-Names="Trebuchet MS" CssClass="btn btn-info" Font-Bold="True" />
</ItemTemplate>
<HeaderTemplate>Comment</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:Button ID="btnDetail" runat="server" Text="view" OnClick="btnDetails_Click" CausesValidation="false" Font-Names="Trebuchet MS" CssClass="btn btn-comment" ForeColor="White" Font-Bold="True" />
</ItemTemplate>
<HeaderTemplate>Details</HeaderTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="bttnHidden" runat="Server" Style="display: none" />
<br />
<asp:Panel ID="pnlComment" runat="server" Width="650px" Height="620px" Style="display: none;" CssClass="modalBox">
<table border="1" class="commentTable" style="border-collapse: separate; border-spacing: 10px; width:100%; height:100%">
<tr><th><asp:Label ID="lblComments" runat="server" Text="Comments" Font-Size="Medium"></asp:Label></th></tr>
<tr><td>
<asp:TextBox ID="txtExistingComments" runat="server" TextMode="MultiLine" ReadOnly="True" CssClass="content" Rows="12" Font-Names="Trebuchet MS"></asp:TextBox>
</td></tr>
<tr><th><asp:Label ID="lblNewComment" runat="server" Text="Add Comment" Font-Size="Medium"></asp:Label></th></tr>
<tr><td>
<asp:TextBox ID="txtNewComments" runat="server" TextMode="MultiLine" ReadOnly="False" CssClass="content" Rows="12" Font-Names="Trebuchet MS"></asp:TextBox></td></tr>
<tr><td>
<asp:Button ID="btnSave" runat="server" width="100px" Text="Save" OnClick="btnSave_Click" CssClass="btn btn-comment" ValidationGroup="SaveComment" ForeColor="White" Font-Bold="True" />
<asp:Button ID="btnCancel" runat="server" width="100px" Text="Cancel" CssClass="btn btn-comment" ForeColor="White" Font-Bold="True"/></td></tr>
<tr>
<td>
<asp:RequiredFieldValidator ID="rfValidator" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="txtNewComments"
ForeColor="Black" ValidationGroup="SaveComment" Font-Bold="True">You must enter a comment!</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</asp:Panel>
<cc1:ModalPopupExtender ID="modal" runat="server" TargetControlID="bttnHidden" PopupControlID="pnlComment" CancelControlID="btnCancel" BackgroundCssClass="modalBackground"></cc1:ModalPopupExtender>
<br />
<asp:HiddenField ID="Hidden" runat="server" value="-1"/>
<asp:HiddenField ID="bStatus" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" ChildrenAsTriggers="false" UpdateMode="Conditional" DisplayAfter="10">
<ProgressTemplate>
<div class="center">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/Images/loader.gif" AlternateText="Please wait ..." ToolTip="Please wait ..." />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
Any help would be most appreciated!
two points you need to check.
First if you have any javascript errors - this Update Progress is base on javascrip, so any javascript error can stop the function of it. Open the console panel and check for javascript errors...
The second point is to check the DisplayAfter property on UpdateProgress, that is 500 milliseconds default value. If anything happens within this time, the UpdateProgress is not show. So add a lower value on DisplayAfter to check it out.
I have the following code
<asp:Content ID="headContent" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
<DataControls>
<asp:DataControlReference ControlID="FormView1" />
</DataControls>
</asp:DynamicDataManager>
<h2 class="DDSubHeader">
Edit entry from table
<%= table.DisplayName %></h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1"
Display="None" CssClass="DDValidator" />
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Edit"
OnItemCommand="FormView1_ItemCommand" OnItemUpdated="FormView1_ItemUpdated" RenderOuterTable="false"
OnPageIndexChanging="FormView1_PageIndexChanging">
<EditItemTemplate>
<table id="detailsTable" class="DDDetailsTable" cellpadding="6">
<asp:DynamicEntity runat="server" Mode="Edit" />
<tr class="td">
<td colspan="2">
<asp:LinkButton runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
<br />
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="lblMessage" runat="server">
</asp:Label>
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" />
</td>
</tr>
</table>
</EditItemTemplate>
<EmptyDataTemplate>
<div class="DDNoItem">
No such item.</div>
</EmptyDataTemplate>
</asp:FormView>
<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true" />
<asp:QueryExtender TargetControlID="DetailsDataSource" ID="DetailsQueryExtender"
runat="server">
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</ContentTemplate>
</asp:UpdatePanel>
This file was generate using Dynamic Data. I am trying to add a file upload control in the form but in the code behind I can't acces 'FileUpload1' to see if it contains elements.
How can I do that?
If I make a new form it works but I can't get it out to work in my existing form.
<form id="form1" runat="server"></form>
It's common issue.
You are trying to upload file on ajax request calling upload from update panel.
But you need full postback to upload it using serious FileUpload or look for javascript based file upload controls.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<asp:Repeater ID="rpChat" runat="server" OnItemDataBound="rpChat_ItemDataBound" OnItemCommand="rpChat_ItemCommand">
<ItemTemplate>
<div id="divChatWindow" title='<%# Eval("username") %>' runat="server" class="clChatWindow">
<div>
<asp:Label runat="server" Text='<%# Eval("username") %>' class="divHeader"></asp:Label>
<img src="../../Menu/close.jpg" onclick="HideDiv(this)" style="float: right; width: 20px;
height: 20px;" /></div>
<div class="chatText">
<asp:Repeater ID="rpChatMessages" runat="server">
<ItemTemplate>
<asp:Image ID="imageForFriend" runat="server" CssClass="clFriendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"fromusername").ToString() %>' />
<asp:Label ID="chatMessage" runat="server" Text='<%# Eval("Message") %>'></asp:Label>
<br>
</ItemTemplate>
</asp:Repeater>
</div>
<asp:TextBox ID="txtChatMessage" runat="server" Width="115px"></asp:TextBox>
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("username") %>'>Send</asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
I have edited the code... Now what should I do? I have the linkbutton inside contenttemplate. Still a postback is happening
Any postback coming from any control outside an UpdatePanel will trigger a full postback unless you add those events as triggers of your UpdatePanel
In your example,
<asp:LinkButton ID="btnSendChat" runat="server" CommandName="Insert" CommandArgument='<%# Eval("Username2") %>'>Send</asp:LinkButton>
It's outside of the UpdatePanel and since you do not have triggers in your panel that will always cause a full postback
Solutions:
Approach 1
Place the LinkButton inside the UpdatePanel.ContentTemplate
Approach 2
Add triggers to your UpdatePanel
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSendChat" EventName="Click" />
</Triggers>
I have two dropdownlist and i want when fist and second dropdownlist triger then fill updatepanel_sehiri_izmir_radiolist but i cant create dynamic radiobutonlist.i think use datalist and radiobuton list .but i cant run code
<asp:UpdatePanel ID="UpdatePanel_sehiri_izmir_radiolist" runat="server" ChildrenAsTriggers="True"
UpdateMode="Conditional">
<ContentTemplate>
<asp:DataList ID="DataList_sehiri_izmir_yeni" runat="server" DataSourceID="SqlDataSource_sehir_izmir"
OnItemCommand="DataList_sehiri_izmir_yeni_ItemCommand">
<ItemTemplate>
<asp:RadioButtonList ID="rb_sehiri_izmir" runat="server" AutoPostBack="True" RepeatDirection="Horizontal"
CommandArgument="gonder" RepeatColumns="1" RepeatLayout="Flow" OnSelectedIndexChanged="rb_sehiri_izmir_SelectedIndexChanged">
<asp:ListItem id="TestedYes" runat="server" Value='<%# Eval("imp_id") %>' Text='<%# Eval("imp_id") %>' />
<asp:ListItem id="TestedNo" runat="server" Value="False" Text="No" />
</asp:RadioButtonList>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource_sehir_izmir" runat="server" ConnectionString="<%$ ConnectionStrings:Web_KentrehberiConnectionString %>"
SelectCommand="SELECT * FROM [Important_places]"></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="drp_sehiri_izmir_ulke_adi" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="drp_sehiri_izmir_sehir_adi" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
I getting issue with MaintainScrollPositionOnPostback with UpdataPanel in TestPage.aspx
page.
Page Header :
<%# Page Language="C#" MasterPageFile="~/MasterPages/Abc.master" AutoEventWireup="true"
MaintainScrollPositionOnPostback="true" CodeFile="Testpage.aspx.cs" Inherits="Testpage"
Title="Test Page" %>
I registered Ajaxtoolkit Control to my aspx page.
with
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
When I add " MaintainScrollPositionOnPostback="true" "page directive to my .aspx page
then I got the error message as shown in attached image.
Error: Status code returns from server:500
my Code
<asp:updatepanel id="upAnatomicalConfig" runat="server" updatemode="Conditional">
<ContentTemplate>
<div id="divform" style="width: 98%; text-align: left; margin: 0 auto" class="W_B">
<div>
<asp:validationsummary id="valsum" runat="server" validationgroup="abc" showmessagebox="true"
displaymode="BulletList" enableclientscript="true" showsummary="false" />
</div>
<!-- Here is some text box that I used for Save -------->
<asp:button id="btnSave" runat="server" text="Save" cssclass="button" causesvalidation="true"
validationgroup="abc" onclick="btnSave_Click" />
<asp:button id="btnCancel" runat="server" text="Cancel" cssclass="button" onclick="btnCancel_Click"
causesvalidation="false" />
<asp:datagrid id="dtgrid" runat="server" width="100%" cssclass="dgGrid" onitemdatabound="dtgrid_ItemDataBound"
cellpadding="2" autogeneratecolumns="false" showfooter="true" showheader="true"
onitemcreated="dtgrid_ItemCreated" allowpaging="True" pagesize="25" allowcustompaging="True"
gridlines="None" allowsorting="true" borderwidth="0px" borderstyle="None" onpageindexchanged="dtgrid_PageIndexChanged"
onsortcommand="dtgrid_OnSortCommand">
<Columns>
<asp:TemplateColumn HeaderStyle-Width="5%" ItemStyle-Width="5%">
<ItemTemplate>
<asp:ImageButton ID="ibtnEdit" CausesValidation="false" OnClick="ibtnEdit_Click"
runat="server" ImageUrl="~/Images/Edit.gif" ToolTip="Edit Template" CommandArgument='<%# Eval("tblID") %>'>
</asp:ImageButton>
<asp:ImageButton ID="ibtnDisc" CausesValidation="false" OnClick="ibtnDisc_Click"
runat="server" ImageUrl="~/Images/inactive_record.gif" ToolTip="Move to inactive"
CommandArgument='<%# Eval("tblID") %>'></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSave" />
</Triggers>
</asp:updatepanel>
What is the reason behind that?
Page directive - "MaintainScrollPositionOnPostback" not worked
Reason is that 1) Framework 2.0 and 2) AjaxToolkit (ver 1.0.2....) Reset Position after AJAX (async call) postback not supported.