ASP.NET Auto refresh gridview updatepanel timer - asp.net

Hi
I'm new to ajax.
I'm working on visual studio 2005. I install the ajax Min4setup and I add the control toolkit to the controls toolbar.
I created a new website Ajax-Enabled then I add the existing items (all the page) from the old web site to the new one.
I wrote the code below in the page.aspx and the other code in page.aspx.vb but nothing happens, the timer event is not firing.
Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="8000" Enabled="true">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="test" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="616px" BorderStyle="Outset">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="Sender" HeaderText="Sender"
SortExpression="MO_NICKNAME_SOURCE_LOG_HIS" />
<asp:BoundField DataField="DataChat" HeaderText="Conversation" SortExpression="DataChat" />
<asp:TemplateField HeaderText="Date" SortExpression="DATETIMEIN_LOG_HIS">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OfflineChat_ConnectionString %>"
SelectCommand="SP_GET_OFFLINE_USER_CHAT" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="MO_OFFLINEUSER" SessionField="ID" Type="String" />
<asp:QueryStringParameter Name="MO_NICKNAME_REALUSER" QueryStringField="realuserNick"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
{
Label1.Text = "Grid Refreshed at: "
'& DateTime.Now.ToString
GridView1.DataBind()
UpdatePanel1.Update();
}
Any idea or suggestion will be highly appreciated.
Best Regards,

Start the timer with timer1.Start().
Clear the GridView, set GridView1.DataSet = null and reload the Bindings.

Related

Need a Gridview to Change when DropDownList changes

I have a dropdownlist in ASP.Net (I am using VB.Net) and my ASP.Net code follows. What I would like to do is have that Girdview populate dynamically off of the DropDownList. If the first option (showing nothing) is chosen, I would like everything possible in the Gridview to show. If one of the other options is chosen, I would like the GridView to filter based on that option. I can see the DropDownList, but nothing shows up in the Gridview. I imagine the issue has to do with binding the DropDownList to the Gridview somehow.
Thanks in advance.
<%# Page Title="Home Page" Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="SAP._Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Tab Container Tips & Tricks</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Screening">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Pull For Screening "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem>10</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Add Applicants" />
<asp:Label ID="Label3" runat="server" Text="Choose Campus: "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem Text="All" Value="%"></asp:ListItem>
<asp:ListItem>RC</asp:ListItem>
<asp:ListItem>HS</asp:ListItem>
<asp:ListItem>TL</asp:ListItem>
<asp:ListItem>PH</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ScreenerView %>" ProviderName="<%$ ConnectionStrings:ScreenerView.ProviderName %>"
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME], [APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD], [PullDate], [First] FROM [vw_Screener]"
FilterExpression="Screener ID LIKE '?' AND First LIKE '?'">
<SelectParameters>
<asp:Parameter Name="intS" />
</SelectParameters>
<FilterParameters>
<asp:ControlParameter ControlID="DropDownList2" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ScreenerID" HeaderText="ScreenerID" SortExpression="ScreenerID" Visible="False"></asp:BoundField>
<asp:BoundField DataField="LEGAL_FNAME" HeaderText="First Name" SortExpression="LEGAL_FNAME" />
<asp:BoundField DataField="LEGAL_LNAME" HeaderText="Last Name" SortExpression="LEGAL_LNAME" />
<asp:BoundField DataField="APPL_PERSON_ID" HeaderText="APPL_PERSON_ID" SortExpression="APPL_PERSON_ID" Visible="False" />
<asp:BoundField DataField="AAMC_ID" HeaderText="AAMC" SortExpression="AAMC_ID" />
<asp:BoundField DataField="GENDER" HeaderText="Gender" SortExpression="GENDER" />
<asp:BoundField DataField="URM" HeaderText="URM" SortExpression="URM" />
<asp:BoundField DataField="RecMCAT" HeaderText="MCAT" SortExpression="RecMCAT" />
<asp:BoundField DataField="SciGPA" HeaderText="Sci. GPA" SortExpression="SciGPA" />
<asp:BoundField DataField="LEGAL_RES_STATE_CD" HeaderText="State" SortExpression="LEGAL_RES_STATE_CD" />
<asp:BoundField DataField="PullDate" HeaderText="Date Pulled" DataFormatString = "{0:d}" SortExpression="PullDate" />
<asp:BoundField DataField="First" HeaderText="First Choice CC" SortExpression="First" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</ContentTemplate>
</cc1:TabPanel>
You need to fix your FilterExpression and FilterParements in your SQLDataSource:
In your ASPX File you need to make the following changes:
FilterParameters: The items in this list will be used by the FilterExpression. If this is emtpy then your FilterExpression will have nothing to work with. However, you have ONE item in there, now you must link it to the FilterExpression with its index. Since you have ONE item then its index will be 0 (see filterexpression below). I assume its the [ScreenerID] so its probably an Int32? Then you need to specify that and set a defaultvalue:
<FilterParameters>
<asp:ControlParameter Name="ScreenerID" ControlID="DropDownList2"
PropertyName="SelectedValue" Type="Int32" DefaultValue="" />
</FilterParameters>
FilterExpression: The way you have it now is not correct because it is NOT linked with any real value say User-Interace (Dropdown) . You must link it based on its index/position in the FilterParameter items. Like we said above, since ScreenerID is the first item then it has index 0:
FilterExpression="ScreenerID = {0}"
DropDownList2: Since you already have AutoPostBack="True" you just need add event OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
If ScreenID is an integer, you need to remove the % from the value field in the ALL item like so: <asp:ListItem Value="" Text="ALL>
VB.NET Code-Behind: In your DropDownList2_SelectedIndexChanged event dont put any code in it. Like so:
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
'Leave empty
End Sub
Let me know if this is not working for you, I can update this answer as I find out more from you.

Pass a session variable to filterParameter in ASP.Net

I am working in ASP.Net. I am attempting to pass a session variable to a gridview control. When I remove the session variable parameter, the dropdownlist I am using to feed the gridview works correctly. When I add the session variable, it shows everything.
Here is my code behind for the page load event (I am using VB.net):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ScreenerID As Int32
Dim intS As Int32
Session("ScreenerID") = 20
intS = CType(Session.Item("ScreenerID"), Int32)
End Sub
My ASP.Net code is as follows:
<%# Page Title="Home Page" Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="SAP._Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Screening Portal</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Screening">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Pull For Screening "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem>10</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Add Applicants" />
<asp:Label ID="Label3" runat="server" Text="Choose Campus: "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Text="All" Value=""></asp:ListItem>
<asp:ListItem>CRC</asp:ListItem>
<asp:ListItem>GHS</asp:ListItem>
<asp:ListItem>STL</asp:ListItem>
<asp:ListItem>WPH</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ScreenerView %>" ProviderName="<%$ ConnectionStrings:ScreenerView.ProviderName %>"
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME], [APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD], [PullDate], [First] FROM [vw_Screener]"
FilterExpression="ScreenerID = {0} AND First='{1}'">
<FilterParameters>
<asp:Parameter Name="intS" Type="int32" />
<asp:ControlParameter ControlID="DropDownList2" PropertyName="SelectedValue" Type="String" DefaultValue=""/>
</FilterParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ScreenerID" HeaderText="ScreenerID" SortExpression="ScreenerID" Visible="False"></asp:BoundField>
<asp:BoundField DataField="LEGAL_FNAME" HeaderText="First Name" SortExpression="LEGAL_FNAME" />
<asp:BoundField DataField="LEGAL_LNAME" HeaderText="Last Name" SortExpression="LEGAL_LNAME" />
<asp:BoundField DataField="APPL_PERSON_ID" HeaderText="APPL_PERSON_ID" SortExpression="APPL_PERSON_ID" Visible="False" />
<asp:BoundField DataField="AAMC_ID" HeaderText="AAMC" SortExpression="AAMC_ID" />
<asp:BoundField DataField="GENDER" HeaderText="Gender" SortExpression="GENDER" />
<asp:BoundField DataField="URM" HeaderText="URM" SortExpression="URM" />
<asp:BoundField DataField="RecMCAT" HeaderText="MCAT" SortExpression="RecMCAT" />
<asp:BoundField DataField="SciGPA" HeaderText="Sci. GPA" SortExpression="SciGPA" />
<asp:BoundField DataField="LEGAL_RES_STATE_CD" HeaderText="State" SortExpression="LEGAL_RES_STATE_CD" />
<asp:BoundField DataField="PullDate" HeaderText="Date Pulled" DataFormatString = "{0:d}" SortExpression="PullDate" />
<asp:BoundField DataField="First" HeaderText="First Choice CC" SortExpression="First" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="Query">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Search "></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="Manage Invitations">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel4" runat="server" HeaderText="Reports">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel5" runat="server" HeaderText="Admin">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<br />
</div>
</form>
</body>
</html>
I imagine I am doing something simple that needs a quick fix, but it is beyond me. Thank you.
Since intS doesn’t change much, why don’t you feed it into the select statement instead of applying a filter parameter? what do you think?
ASPX SqlDataSource1:
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME],
[APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD],
[PullDate], [First]
FROM [vw_Screener]
WHERE [First] = #First" <-- Notice the WHERE Clause
Remove <asp:Parameter Name="intS" Type="int32" /> from FilterParameters and then change your FilterExpression to:
FilterExpression="First='{0}'"
But you must add [First] as a parameter in the SelectParameters section like so:
<SelectParameters>
<asp:Parameter Name="First" />
</SelectParameters>
VB.NET Code-Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ScreenerID As Int32
Dim intS As Int32
Session("ScreenerID") = 20
intS = CType(Session.Item("ScreenerID"), Int32)
SqlDataSource1.SelectParameters.Add("#First ",intS) '<-- Here is where we set intS
End Sub

asp.net one more updatepanel is not working

I added 3 updatepanel on a aspx page.Two updatepanel includes gridview.And i make gridview paging.two buttons fill this gridviews when clicked.I set both of them triggers and conditional state.Third updatepanel includes textbox.And i set updatemode conditional,triggers third button.
That my question,when i click firstly third button i select checked datafield from gridview,run succesfully.
But when i click after one clicked,third updatepanel and gridview paging is not working.
<asp:UpdatePanel ID="UpdatePanelWorkFLow" runat="server">
<%--<Triggers>
<asp:PostBackTrigger ControlID="btnGenerate" />
</Triggers>--%>
<ContentTemplate>
<asp:GridView ID="GridWorkFlow" runat="server" AllowPaging="True" AutoGenerateColumns="False"
EnableSortingAndPagingCallbacks="false" CellPadding="4" ForeColor="#333333" GridLines="None"
OnPageIndexChanging="GridWorkFlow_PageIndexChanging">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ShowHeader="true" HeaderText="Seç">
<ItemTemplate>
<asp:CheckBox ID="checkWorkFlow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="labelWorkFlowId" runat="server" Text='<%# Eval("WorkFlowId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WorkFlow Adi">
<ItemTemplate>
<asp:Label ID="labelWorkFlowName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birincil Entity Adi">
<ItemTemplate>
<asp:Label ID="labelPrimaryEntity" runat="server" Text='<%# Bind("PrimaryEntity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText="Durum Açiklamasi">
<ItemTemplate>
<asp:Label ID="labelWorkFlowStaus" runat="server" Text='<%# GetStatusCodeText(DataBinder.Eval(Container.DataItem,"StatusCode"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWorkFLow" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
my gridview paging code
WorkFlowDataBind();
GridWorkFlow.PageIndex = e.NewPageIndex;
GridWorkFlow.DataBind();
my third button code
string userQueryId = GetUserQueryId();
string userqueryName = GetUserQueryName();
string workFlowId = GetWorkFlowId();
string primaryEntityName = GetWorkFlowPrimaryEntity();
GetWorkFlowName();
my one and second button when clicked load gridview
Datatable dtUserQuery=GetDataTable();
GridUserQuery.DataSource = dtUserQuery;
GridUserQuery.DataBind()
How can i fix.
Logic is .. If you have one or more update panel in the same page then properties of all update panel should be same such as if update panel data are dependency on each other
Update Mode : Always
EnableViewState : true(if you are using it)
Or you can explicitly update the Update panel when mode is conditional
Let us say you have two update panel like up1 and up2.
You have placed the label in the up1 and the other form or button placed in the up2.
Now on the click event in the up2, label placed in the up1 should be updated without loading the full page. Set the following stuffs
Set EnableParitialRendering ='True'(Script Manager)
Set Update Mode :Conditional(up1)
Set Update Mode : Always (up2). All set up done here. On click of a button in the up2, do your work and call up1.Update(); That's all.

DomEvent. AddHandler

I am facing little issue in my web application in asp.net.
i am receiving the below error :
Error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.
I have used Updatepanel and this error occurs when i try to do some 2-3 actions very quickly.
and when next time i try to do take some action my web application just hungs up.
Please suggest.
Thanks
In my case this was caused by having the 'Close' control within an Update Panel in the Modal Popup. I fixed it by creating a 'dummy' button outside of the Update Panel, and setting it as the 'CancelControlID' in the MPE attributes:
<asp:Button ID="btnDummyCloseWindow" runat="server" Style="visibility: hidden"/>
<ajaxToolkit:ModalPopupExtender ID="mpeWindow" runat="server" PopupControlID="pnlWindow"
TargetControlID="btnDummyOtherButton" BackgroundCssClass="modalBackground"
DropShadow="false" CancelControlID="btnDummyCloseWindow" />
You'll need to make sure the close button that is present within your Update Panel has actions assigned to it to close the window (e.g. mpeWindow.hide()).
It's also worth noting that I was also making use of the TargetControlID 'fix' too, where a dummy button is referenced, so ignore the TargetControlID attribute there.
I've solved the problem setting ScriptMode property of ScriptManager to Release instead of Debug
By default ScriptManager is set to Debug mode.
I had the same problem and solved by placing the ModalPopupExtender or the user control that uses ModalPopupExtender inside an update panel.
Which ever way you want to look at it, the problem is inherit in what I believe is a bug in AJAX.
The only way I was able to resolve this was to control your Sorting or Paging on the server side where you control or more specifically refresh the UpdatePanel along with making sure the ModalPopup has been kept visible!
The reason for the error is really because once you do a sort of page change on a GridView that's inside an UpdatePanel, the controls have been "lost" to the UpdatePanel.
A better explanation is here.
Here is a column from my GridView...
<asp:GridView ID="gvTETstudents" runat="server" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" ForeColor="#333333" Font-Size="Small" Width="100%"
DataSourceID="sdsTETstudents"
OnRowCreated="gvTETstudents_RowCreated"
OnRowDataBound="gvTETstudents_RowDataBound"
OnDataBound="gvTETstudents_DataBound">
<Columns>
..
..
<ItemTemplate>
<asp:UpdatePanel ID="upWEF1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWEFCLOSE" />
</Triggers>
<ContentTemplate>
...
...
<asp:Panel ID="pnlWEF2" runat="server" style="display:none;">
<table><tr><td>
<asp:Button ID="btnWEFshow" runat="server"
Text="ALL"
Font-Size="Small" Font-Names="Arial"
ToolTip="Click here to see all of this student's work experience feedback on file" />
<ajaxToolkit:ModalPopupExtender ID="mpeWEF" runat="server"
BackgroundCssClass="modalBackground"
OkControlID="btnWEFCLOSE"
PopupControlID="upWEF2"
TargetControlID="btnWEFshow">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEF2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlWEF3" runat="server" CssClass="pnlEndorsed">
<div id="Hdr" style="text-align: center">
<asp:Label ID="lblWEFHdr" runat="server">** CONTACT LOG **</asp:Label>
</div>
<div id="Bdy">
<table style="width:100%"><tr><td>
<asp:GridView ID="gvWEFContactLog" runat="server"
Font-Size="X-Small" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" AllowSorting="True" AutoGenerateColumns="False" Width="100%"
DataKeyNames="StudentContactLogID,Private,ApprenticeContactLogID"
DataSourceID="sdsWEF"
OnRowDataBound="gvWEFContactLog_RowDataBound"
OnPageIndexChanging="gvWEFContactLog_PageIndexChanging"
OnSorted="gvWEFContactLog_Sorted">
<Columns>
<asp:TemplateField HeaderText="First Entered" SortExpression="FirstEntered">
<ItemTemplate>
<asp:HiddenField ID="hfWEFStudCLid" runat="server" Value='<%# Eval("StudentContactLogID") %>' />
<asp:HiddenField ID="hfWEFAppCLid" runat="server" Value='<%# Eval("ApprenticeContactLogID") %>' />
<asp:HiddenField ID="hfPrivate" runat="server" Value='<%# Eval("Private") %>' />
<asp:HiddenField ID="hfNotes" runat="server" Value='<%# Eval("ContactNotes") %>' />
<asp:LinkButton ID="lnkWEFCLOG" runat="server"
Text='<%# Eval("FirstEntered","{0:d MMM yyyy HH:mm}") %>'></asp:LinkButton>
<a id="lnkDummy" runat="server" visible=false></a>
<ajaxToolkit:ModalPopupExtender ID="mpeWEFCLOG" runat="server"
OkControlID="btnWEFCLOSEview"
PopupControlID="upWEFCLOG"
TargetControlID="lnkWEFCLOG">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEFCLOG" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="pnlWEFCLOG" runat="server" class="pnlCLOG">
<asp:TextBox ID="txtWEFCLOG" runat="server"
Wrap="true"
TextMode="MultiLine"
Rows="10"
ReadOnly="true"
Width="98%">
</asp:TextBox>
<br />
<asp:Button ID="btnWEFCLOSEview" runat="server" Text="OK" Width="100%" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:BoundField Visible="False" DataField="StudentContactLogID" HeaderText="LogID"
InsertVisible="False" ReadOnly="True" SortExpression="StudentContactLogID">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="StaffName" HeaderText="Staff" ReadOnly="True" SortExpression="StaffName" />
<asp:TemplateField HeaderText="Contact Date Time" SortExpression="ContactDateTime">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactDateTime","{0:d MMM yyyy HH:mm}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Follow-Up Date" SortExpression="FollowUpDate">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("FollowUpDate","{0:d MMM yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Private" HeaderText="Private" SortExpression="Private" />
</Columns>
<EmptyDataTemplate>
No Current Entries
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="sdsWEF" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="spTETStudentContactLogView" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:Parameter Name="WEF" Type="string" DefaultValue="%" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr style="text-align: center">
<td style="text-align: left">
<asp:Button ID="btnWEFCLOSE" runat="server"
Text="CLOSE"
CausesValidation="false" Font-Bold="True" Width="61px" />
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</td></tr></table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
The major point of the code above is that I have a very deep GridView inside an UpdatePanel that's inside a ModalPopUp.
Now look at what I have inside that GridView:
OnPageIndexChanging
and
OnSorted
Inside the GridView, there is another ModalPopup and TextBox. Ignore that. That's only so the user can see the comments from the student's contact log as another popup window.
So if we now go to the code behind for the above two events:
protected void gvWEFContactLog_Sorted(object sender, EventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
protected void gvWEFContactLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
Notice that I am not actually controlling the sorting or the paging itself. I am only forcing the GridView to call upon the main UpdatePanel (upWEF1) to refresh itself via an Update() call. The next step is to grab the ModalPopup I want to keep visible and re-Show() it!
And that's all there is to it!
I am sure there is a cleaner solution using JavaScript itself, but for me this avoids that dread meaningless error and I have a clean set of popups and update panels that can handle both hotlinks, sorting and paging as I want the GridView to perform!

ASP.NET 3.5 UpdatePanel with Validation Control. Validation runs unexpectedly

I've got a ASP.NET 3.5 sp1 site, and on one page I have two UpdatePanels. The first has a CustomValidator, and the second does not. I want the validation to run ONLY when the button is pressed. Currenlty, when the Gridview in the second updatepanel is edited, it also causes the validation. I've read a lot about how the validation controls in 2.0 used to be messed up, but I'm pretty sure that's not germaine to my problem here (or is it?)
Here's the relevant section of the page...
<asp:UpdatePanel ID="userInput" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtMCCredits" runat="server" Width="28px"></asp:TextBox>
<asp:CustomValidator ID="UserValidator" runat="server" ErrorMessage="*" OnServerValidate="UserValidator_ServerValidate" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:UpdatePanel ID="upData" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvMainproCredits" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvMainproCredits" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" DataKeyNames="RecordID">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<!--SNIP-->
<asp:BoundField DataField="RecordID" HeaderText="RecordID" InsertVisible="False"
ReadOnly="True" SortExpression="RecordID" Visible="false" />
<asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
<asp:CommandField ShowHeader="true" HeaderText="Edit" ShowEditButton="true" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
You might want to partition the validations using ValidationGroup.
In that way, you can choose to have the button validating only certain controls within the same group.
Only part of the solution, but here is a link how to manually call client-side validation in javascript.
the simpler is:
Page_ClientValidate('Group1');

Resources