Turn off PostBack on a menu click? - c#

I have pagination in an UpdatePanel.
I have a dropdownlist that controls which field will be sorted on.
I have added both the sort button and the pagination menu as AsyncPostBackTriggers. My sort button works fine, but my pagination menu resets the sort dropdownlist to the default value every time I click it. When I step through the code, I can see the sort button fires the (!IsPostBack) section, and the pagination menu fires the "Else" section of my page load.
So, I can click any page and it works fine. I can sort and it will return the proper records sorted for that page. When I click on a page number again, the sort returns to the default. I want to allow my users to sort one time and then page through the sorted data.
So, how can I turn off PostBack on a menu?
My relevant code looks like this:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
<table>
<tr>
<td width="150">
<asp:DropDownList ID="cboSortBy" runat="server" Width="120" ViewStateMode="Enabled">
<asp:ListItem Value="StatusText">Benefit Type</asp:ListItem>
<asp:ListItem Value="PRIORITY_RANK">Priority Rank</asp:ListItem>
<asp:ListItem Value="ACTIVE_FLG">Active Flag</asp:ListItem>
</asp:DropDownList>
</td>
<td width="180"><asp:Button ID="btnSort" runat="server"
Text="Sort" Width="121px" onclick="btnSort_Click" /></td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" Font-Bold="True" />
<br />
<div class="clear" id="NavDiv" style="width:1000px; margin:0 auto; display: table;">
<asp:Menu ID="NavMenu" runat="server" CssClass="navmenu"
IncludeStyleBlock="false" Orientation="Horizontal" width="703px"
BackColor="#CC3300">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="First" Selectable="true" />
</Items>
</asp:Menu>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table width="570">
<tr>
<td>
<asp:UpdatePanel ID="SearchPanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="NavMenu" />
<asp:AsyncPostBackTrigger ControlID="btnSort" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="BenTypeRepeater" runat="server" onitemcommand="Repeater2_ItemCommand">
<HeaderTemplate>
<table>
<tr bgcolor="#007ACC" style="color:White">
<td></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td colspan = "2"></td>
<tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="5"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>

Add AutoPostBack="true" to dropdown
<asp:DropDownList ID="cboSortBy" runat="server" Width="120" ViewStateMode="Enabled" AutoPostBack="true">
<asp:ListItem Value="StatusText">Benefit Type</asp:ListItem>
<asp:ListItem Value="PRIORITY_RANK">Priority Rank</asp:ListItem>
<asp:ListItem Value="ACTIVE_FLG">Active Flag</asp:ListItem>
</asp:DropDownList>

Related

Render UserControl in Same line as other controls in a <td>

I want to render Usercontrol in the same line as my other controls in . By default, it renders in new line for user control.
Here is my Markup
<tr>
<td>
<asp:ContentPlaceHolder ID="TitleContentPlaceHolder" runat="server">
<asp:Label ID="lblTitle" runat="server" EnableTheming="False" Font-Size="Small" ForeColor="Green"
Font-Bold="True" Style="margin-left: 18px"></asp:Label>
<asp:HyperLink ID="gotoHyperLink" Visible="false" EnableTheming="False" Font-Size="Small"
ForeColor="Green" Font-Bold="True" Style="margin-left: 2px" runat="server" NavigateUrl=""
Target="_blank">- To Wiki</asp:HyperLink>
<uc1:GoToRequestControl ID="GoToRequestControl1" runat="server" />
</asp:ContentPlaceHolder>
</td>
</tr>
I want to render the UC1 in the same line as previous two controls in Div if possible after some spacing to the right. Any fix on how to achieve this?
My User Control is designed using despite that I want it to be on same line. Here is my Usercontrol's HTML
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Panel runat="server" DefaultButton="btnGo" BackColor="Transparent">
<table style="margin-left:18px">
<tr valign="top">
<td>
<b><asp:Literal ID="Label1" runat="server" Text="Coeus Request ID: " EnableTheming="False"></asp:Literal></b>
</td>
<td>
<asp:TextBox ID="tbRequestId" runat="server" EnableTheming="false" Width="260px"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnGo" runat="server" Text="Go" OnClick="btnGo_Click" OnClientClick="CheckLock();"
CausesValidation="False" UseSubmitBehavior="false" />
</td>
<td>
<asp:Label ID="lblStatus" runat="server" Text="" EnableTheming="False" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>

How will use multiple fileupload in same Asp net page

In my Project I add three FileUploder.I have already used UpdatePanel in my page. also I had given Updatepanel each fileuploder. My problem is that when I click on the button Edit, FileUploader didnot take selected file.I need postfile from every fileuploader.also
I add trigger for the button btnEdit,but on Click event none of the fileuploader take selcted file.
How will manage this three file uploder in this page. I mentioned my code below.
<table class="ui-accordion">
<asp:UpdatePanel ID="updatepanel1" runat="server"><ContentTemplate>
<tr>
<td align="left" class="style2">
<asp:Label ID="Label14" runat="server" Text="Experience Certificate"></asp:Label>
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload2" runat="server" /><asp:Image ID="Img1"
runat="server" Height="33px" Width="36px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Label14" runat="server" Text="Experience Certificate"></asp:Label>
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload3" runat="server" /><asp:Image ID="Img1"
runat="server" Height="33px" Width="36px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Label14" runat="server" Text="Experience Certificate"></asp:Label>
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" /><asp:Image ID="Img1"
runat="server" Height="33px" Width="36px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class="style2">
<%--
<asp:Button ID="Button3" class="btn-primary" runat="server" Text="Next"
Height="36px" Width="74px" /> --%>
<asp:HiddenField ID="Hfedi" runat="server" Value=" " />
</td>
<td align="left">
<asp:Button ID="btnEdit" class="btn-primary" runat="server" Text="Edit"
Height="36px" Width="74px" onclick="btnEdit_Click" />
<asp:Label ID="lblmsg" runat="server" ForeColor="Red"> </asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnEdit"/>
</Triggers>
</asp:UpdatePanel>

Child Update Panel don't to get refresh

I have problem in nested update panel. I binding the gridview by using user control and my listbox is in the child update panel while selecting the items in listbox the page is getting refresh. but I don't want to get refresh.
Here is my aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SearchModule._Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<link type="text/css" rel="stylesheet" href="Defaultstylesheet.css" />
<script src=<%--"Scripts/jquery-1.8.2.js" type="text/javascript"> </script> --%>
<%# Register TagPrefix="inc" TagName="sPager" Src="~/UserControls/SearchPager.ascx" %>
<asp:UpdatePanel ID="upseachr" runat="server" >
<ContentTemplate>
<div style="height: 50px;"></div>
<div class="searchtextbx">
<asp:TextBox ID="searchtext" runat="server"></asp:TextBox>
<asp:Button ID="Search" OnClick="Search_Click" CssClass="searchbtn" Text="Search" height="32" runat="server"> </asp:Button>
</div>
<asp:UpdateProgress ID="updatesearchpro" AssociatedUpdatePanelID="upseachr" runat="server" >
<ProgressTemplate>
<center>
<asp:Panel ID="searchpanel" runat="server">
<img alt="Processing" src="Images/359.gif" />
<br />
<asp:Label ID="panlab" runat="server" Text="Processing..."></asp:Label>
</asp:Panel>
</center>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="updFilters" runat="server" >
<ContentTemplate>
<div class="resultpage" style="overflow-x: scroll;">
<table>
<tr>
<div class="listbox">
<asp:Label ID="headertext" runat="server" CssClass="labelresul" Font-Bold="true" Height="50" Text="Available Filter"></asp:Label>
<span style="padding-left:10px;font-weight:700;"> <asp:HiddenField runat="server" ID="hdCount" /><asp:Label ID="Total" runat="server" Height="50"></asp:Label></span><span style="padding-left:5px;font-weight:700;"><asp:Label runat="server" ID="match" Visible="false" Text="Matches"></asp:Label> <asp:Label ID="remainingcount" ForeColor="Red" Visible="false" runat="server"></asp:Label> <asp:Label ID="remaining" runat="server" ForeColor="Red" Text="Remaining" Visible="true"></asp:Label> </span>
</div>
</tr>
<tr>
<asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound" EnableViewState="false">
<ItemTemplate>
<td>
<asp:Label ID="listheader" runat="server" Text='<%# Eval("additional_info_name1") %>'></asp:Label>
<asp:ListBox ID="results" Width="200" Visible="true" runat="server" SelectionMode="Multiple" AutoPostBack="true" OnSelectedIndexChanged="results_SelectedIndexChanged" ></asp:ListBox>
</td>
</ItemTemplate>
</asp:ListView>
</tr>
<tr>
<td class="listbox1">
<asp:Button ID="btn" runat="server" Font-Size="12" Font-Bold="true" CssClass="searchbtn" OnClick="btn_Click" Text="Apply Filter" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div style="height: 40px;"></div>
<div class="resultpage" style="overflow-y: scroll;">
<asp:UpdatePanel ID="updPager" runat="server">
<ContentTemplate>
<inc:sPager ID="sPager" runat="server" OnPageIndexChanging="sPager_OnPageIndexChanging"></inc:sPager>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="updGrid" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvResults" runat="server" AutoGenerateColumns="false" ItemStyle-VerticalAlign="Middle" AllowSorting="true"
ItemStyle-HorizontalAlign="Center" GridLines="None" CellSpacing="10" CellPadding="2" AllowCustomPaging="true" OnSorting="gvResults_Sorting"
AllowPaging="True" PageSize="20" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="GridHeader" RowStyle-HorizontalAlign="Left" CssClass="GridStyle" >
<Columns >
<asp:TemplateField HeaderText="Stock Code" SortExpression="manufacturer_part_number" >
<ItemTemplate>
<asp:Label ID="lblFirstName" Text='<%# DataBinder.Eval(Container.DataItem, "manufacturer_part_number")%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Manufacturer" SortExpression="Manufacturer" HeaderText="Manufacturer"></asp:BoundField>
<asp:BoundField DataField="Description" SortExpression="Description" HeaderText="Description"></asp:BoundField>
<asp:BoundField DataField="Availability" SortExpression="Availability" HeaderText="Availability"></asp:BoundField>
<asp:BoundField DataField="flag_rohs" SortExpression="flag_rohs" HeaderText="RoHS"></asp:BoundField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
It appears that your top-level UpdatePanel has an UpdateModeof Always (which is the default).
The MSDN documentation states:
If the UpdateMode property is set to Always, the UpdatePanel
control's content is updated on every postback that originates from
anywhere on the page. This includes asynchronous postbacks from
controls that are inside other UpdatePanel controls and postbacks
from controls that are not inside UpdatePanel controls.
You can rectify this by changing your top-level UpdatePanel control to conditional. e.g:
<asp:UpdatePanel ID="upseachr" runat="server" UpdateMode="Conditional">
Cheers

First modalpopup in first panel does not open until second modalpopup opens in second panel

I have one updatepanel exists with two panels. Each panel have two buttons to open popup. I have two modalpopup & its target panels just below of two panels.Everything is working fine, but I am getting problem, if I click button in first panel then modalpopup does not open, but when I click button in second panel after click button in first panel then popup opens & viceversa.
I used following code:
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnl1" runat="server">
<asp:Button ID="btn1" runat="server" class="add-btn-1" Text="Add" />
</asp:Panel>
<asp:Panel ID="pnl2" runat="server">
<asp:Button ID="btn2" runat="server" class="add-btn-1" Text="Add" />
</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopup1" PopupControlID="pnlpopup1" TargetControlID="btn1"
BackgroundCssClass="modalBackground" runat="server" />
<asp:Panel runat="server" ID="pnlpopup1">
<%--code here--%>
</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopup2" PopupControlID="pnlpopup2" TargetControlID="btn2"
BackgroundCssClass="modalBackground" runat="server" />
<asp:Panel runat="server" ID="pnlpopup2">
<%--code here--%>
</asp:Panel>
</ContentTemplate>
What will be solution to solve this problem?
Thank you.
I executed your code and found no problems.It works.So post the code that you have given inside <%--code here--%>.I would also suggest that you add a OkControlID to your ModalPopupExtender.
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnl1" runat="server">
<asp:Button ID="btn1" runat="server" class="add-btn-1" Text="Add" />
</asp:Panel>
<asp:Panel ID="pnl2" runat="server">
<asp:Button ID="btn2" runat="server" class="add-btn-1" Text="Add" />
</asp:Panel>
<Ajax:ModalPopupExtender ID="ModalPopup1" PopupControlID="pnlpopup1" TargetControlID="btn1"
BackgroundCssClass="modalBackground" runat="server" />
<asp:Panel runat="server" ID="pnlpopup1" Style="width:400px;height:100px; background: gray;">
<table width="100%">
<tr>
<td align="left">
<asp:Label ID="lblheadinglunchout" Font-Underline="true" Text="First Popup"
runat="server" CssClass="labelPopup" Style="text-decoration: none"></asp:Label>
</td>
<td align="right">
<asp:ImageButton ID="imgbtnCancelPopUp" ImageUrl="Images/popupclose_button.png"
runat="server" Style="vertical-align: top;" CssClass="button" />
</td>
</tr>
</table>
</asp:Panel>
<Ajax:ModalPopupExtender ID="ModalPopup2" PopupControlID="pnlpopup2" TargetControlID="btn2"
BackgroundCssClass="modalBackground" runat="server" />
<asp:Panel runat="server" ID="pnlpopup2" Style="width:400px;height:100px; background: gray;">
<table width="100%">
<tr>
<td align="left">
<asp:Label ID="Label1" Font-Underline="true" Text="Secound Popup"
runat="server" CssClass="labelPopup" Style="text-decoration: none"></asp:Label>
</td>
<td align="right">
<asp:ImageButton ID="ImageButton1" ImageUrl="Images/popupclose_button.png"
runat="server" Style="vertical-align: top;" CssClass="button" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Keep page position on postback

I have a problem:
<asp:Label ID="Label1" runat="server" Text="Name" CssClass="left"></asp:Label>
<asp:LinkButton ID="LinkEdit" runat="server" CssClass="right_bottom"
onclick="LinkEdit_Click" Height="16px">edit</asp:LinkButton>
<asp:LinkButton ID="Linkhide" runat="server" CssClass="right_bottom"
onclick="Linkhide_Click" Visible="False" hide</asp:LinkButton>
<br />
<hr style="width: 740px; height: -6px; margin-left: 0px; " />
<asp:Label ID="labelFullname" runat="server" Text="Full Name" CssClass="left_top"></asp:Label>
<asp:Label ID="labelNameDisplay" runat="server" Text="Put name here" CssClass="right_top"></asp:Label>
<br />
<asp:Panel ID="panelName" runat="server" Height="240px" Visible="False" CssClass="panel_top"
style="text-align: left;">
<asp:Label ID="Label8" runat="server" CssClass="left" Text="Please allow 24 hours for name changes to take effect."></asp:Label>
<div align="center"><br />
<br />
<table>
<tr>
<td class="label_new">
<asp:Label ID="Label4" runat="server" Text="Full Name:" ToolTip="Name Displayed"></asp:Label>
</td>
<td align="left">
<asp:DropDownList ID="DropDownList1" runat="server" BorderStyle="Groove"
Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="25px"
valign="middle" Width="250px">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtFirstName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label9" runat="server" Text="Middle Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtMiddleName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px" onfocus="if (this.value == 'optional') { this.value=''; this.style.color='black';}" />
</td>
</tr>
<tr>
<td class="label_new">
<asp:Label ID="Label10" runat="server" Text="Last Name:"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtLastName" runat="server" BorderStyle="Groove" Font-Names="Segoe UI,Tahoma,Verdana,Arial,Times" Font-Size="100%" Height="20px"
valign="middle" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSaveChanges" runat="server" Text="Save Changes"
onclick="btnSaveChanges_Click" />
</td>
</tr>
</table>
</div>
</asp:Panel>
I have 4 panels in this format just like ACCOUNT SETTINGS on facebook.
My problem here is when I show the panel it just jump to the top of the page.
I would like to do it just as the way facebook is doing. Click and be on at the same position of where you clicked.
You can set the MaintainScrollPositionOnPostback property on your page:
Page.MaintainScrollPositionOnPostback = true;
or put it in the page declaration
<%# Page MaintainScrollPositionOnPostback="true" %>
I'm not entirely sure I what you are asking for. Facebook uses a lot of ajax style callbacks which means that the page doesn't reload using asp .net style postbacks. If you're just starting out I'd recommend you trying placing your code into an Ajax .Net UpdatePanel whilst you learn the details of Ajax / JSON / XMLHttpRequest etc.
If you're simply looking to make sure the browser window remains at the same scrollbar position after a postback then set the page to use the MaintainScrollPositionOnPostback="true" directive.

Categories

Resources