Solved

Why does my OnPageIndexChanging event not fire?

Posted on 2013-01-24
8
643 Views
Last Modified: 2013-01-31
I'm including my ASP page code and my C# code. My OnPageIndexChanging isn't firing and I don't know why. Everywhere else in my app. that this code is being used seems to be working fine. I can't spot the difference. I'll include a page (and the code behind) in which it does work as well.

STUFF THAT'S BROKEN
ASP page that has the problem with OnPageIndexChanging
---------------------------------------------------------------------------------------------

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AthleteInfoGrid.ascx.cs"
    Inherits="UserControls_AthleteInfoGrid" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
<asp:UpdatePanel runat="server" ID="upAthleteInfoPanel" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gdvAthleteInfo" runat="server" AutoGenerateColumns="false" CssClass="SignedInGrid"
            GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="10" PageIndex="0" DataKeyNames="AthleteInfoUid"
            PagerStyle-HorizontalAlign="Center" OnPageIndexChanging="gdvAthleteInfo_OnPageIndexChanging"
            OnRowCommand="gdvAthleteInfo_OnRowCommand" OnRowDataBound="gdvAthleteInfo_OnRowDataBound">
            <Columns>
                <asp:TemplateField HeaderText="Record ID" SortExpression="1" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblAthleteInfoRecordID" runat="server" CssClass="StudentNameLabel"
                                Text='<%# Eval("AthleteInfoUid") %>'></asp:Label><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Ahthlete ID" SortExpression="2" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblAthleteUid" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteUid") %>'></asp:Label><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Ahthlete SSN" SortExpression="3" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxAthleteSSN" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteSSN") %>'></asp:TextBox><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Athlete Last Name" SortExpression="4" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxAthleteLastName" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("LastName") %>'></asp:TextBox><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Athlete First Name" SortExpression="5" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxAthleteFirstName" runat="server" CssClass="StudentNameLabel"
                                Text='<%# Eval("FirstName") %>'></asp:TextBox><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Athlete Name" SortExpression="6" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxAthleteName" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteName") %>'></asp:TextBox><h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Semester Time" SortExpression="7" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblSemesterTime" runat="server" Text='<%# Eval("SemesterTime") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Semester Total Minutes" SortExpression="23" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblSemesterTotal" runat="server" Text='<%# Eval("SemesterTotal") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Warning Count" SortExpression="8" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxWarningCount" runat="server" Text='<%# Eval("WarningCount") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Notes" SortExpression="9" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox runat="server" ID="tbxNotes" CssClass="sinceSignedIn" Text='<%# Eval("Notes") %>'
                                Width="150px" Rows="2" TextMode="MultiLine"></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Week Total Minutes" SortExpression="10" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblWeekTotalMinutes" runat="server" Text='<%# Eval("TotalMinutes") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Week Total" SortExpression="11" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblWeekTotal" runat="server" Text='<%# Eval("WeekTotal") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Required Hours" SortExpression="12" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxRequiredHours" runat="server" Text='<%# Eval("RequiredHours") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Banked Time" SortExpression="13" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblBankedTime" runat="server" Text='<%# Eval("BankedTime") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Banked Minutes" SortExpression="14" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblBankedMinutes" runat="server" Text='<%# Eval("BankedMinutes") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Sport ID" SortExpression="15" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxsportID" runat="server" Text='<%# Eval("SportUid") %>' Visible="false"></asp:TextBox></h2>
                            <asp:DropDownList runat="server" ID="ddlSportTeam" Width="210px"/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Signed In" SortExpression="16" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:RadioButton ID="rbtnSignedIn" runat="server" Checked='<%# Eval("SignedIn") %>'>
                            </asp:RadioButton></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Used Banked Minutes" SortExpression="17" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:Label ID="lblUsedBankedMinutes" runat="server" Text='<%# Eval("UsedBankedMinutes") %>'></asp:Label></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="GPA" SortExpression="18" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxGPA" runat="server" Text='<%# Eval("GPA") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Major" SortExpression="19" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxMajor" runat="server" Text='<%# Eval("Major") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Active" SortExpression="20" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:RadioButton ID="rbtnActive" runat="server" Checked='<%# Eval("Active") %>'>
                            </asp:RadioButton></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Classification" SortExpression="21" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxClassification" runat="server" Text='<%# Eval("Classification") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Start Term" SortExpression="22" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <h2>
                            <asp:TextBox ID="tbxStartTerm" runat="server" Text='<%# Eval("StartTerm") %>'></asp:TextBox></h2>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lkbtnSelect" Text="Save Changes" CommandName="EditStudentInfo"
                            CommandArgument='<%# Eval("AthleteInfoUid") %>' CssClass="button small green" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerSettings Mode="NextPrevious" />
            <PagerStyle CssClass="Paging" />
            <PagerTemplate>
                <div class="Paging">
                    <asp:LinkButton ID="PreviousLinkButton" runat="server" CommandArgument="Prev" CommandName="Page"
                        CssClass="PagerControl" Text="Prev"></asp:LinkButton>
                    <asp:Label ID="PageDescriptionLabel" runat="server" CssClass="PagerControl"></asp:Label>
                    <asp:LinkButton ID="NextLinkButton" runat="server" CommandArgument="Next" CommandName="Page"
                        CssClass="PagerControl" Text="Next"></asp:LinkButton>
                </div>
            </PagerTemplate>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
<div class="updateAlert">
    <asp:Panel runat="server" ID="pnlNoRecordsFound" Visible="false" CssClass="UpdatedMessage Alert SavedSmall">
        <h3>
            No records found.</h3>
    </asp:Panel>
</div>

Open in new window


C# for ASP page that has problem with OnPageIndexChanging
--------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudyTimeTracker.Common.Domain;
using StudyTimeTracker.Public.Business;

public partial class UserControls_AthleteInfoGrid : System.Web.UI.UserControl
{
    public String SidSname
    {
        get
        {
            return Request.QueryString["SidSname"];
        }
    }

    public String FullNameLike
    {
        get
        {
            return Request.QueryString["FullNameLike"];
        }
    }

    public String FirstNameLike
    {
        get
        {
            return Request.QueryString["FirstNameLike"];
        }
    }

    public String LastNameLike
    {
        get
        {
            return Request.QueryString["LastNameLike"];
        }
    }

    public String StudentIdLike
    {
        get
        {
            return Request.QueryString["StudentIdLike"];
        }
    }

    public String AccessLevel
    {
        get
        {
            return Request.QueryString["AccessLevel"];
        }
    }

    public String UpdateSuccessful
    {
        get
        {
            return Request.QueryString["UpdateSuccessful"];
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        //ContentPlaceHolder cph = new ContentPlaceHolder();
        //cph = (ContentPlaceHolder)this.Page.Master.FindControl("MainContent");
        //DropDownList ddlSportTeam = new DropDownList();
        //ddlSportTeam = (DropDownList)cph.FindControl("ddlSportTeam");
        //ddlSportTeam.DataTextField = "ItemText";
        //ddlSportTeam.DataValueField = "ItemValue";
        //ddlSportTeam.DataSource = CommonUIProcessor.GetSportTeams();
        //ddlSportTeam.DataBind();

        if (!IsPostBack)
            BindData();
    }

    protected void BindData()
    {
        StudentListBaseList slbl = new StudentListBaseList();
        ContentPlaceHolder cph = new ContentPlaceHolder();
        Label lbl = new Label();
        
        cph = (ContentPlaceHolder)this.Page.Master.FindControl("MainContent");

        lbl = (Label)cph.FindControl("lblnoRecsFound");

        //DropDownList ddlSportTeam = new DropDownList();
        //ddlSportTeam = (DropDownList)cph.FindControl("ddlSportTeam");
        //ddlSportTeam.DataTextField = "ItemText";
        //ddlSportTeam.DataValueField = "ItemValue";
        //ddlSportTeam.DataSource = CommonUIProcessor.GetSportTeams();
        //ddlSportTeam.DataBind();

        if (!String.IsNullOrEmpty(FullNameLike))
        {
            slbl = StudentListProcessor.FindStudentFullNameLikeAI(FullNameLike);
        }
        else if (!String.IsNullOrEmpty(FirstNameLike))
        {
            slbl = StudentListProcessor.FindStudentFirstNameLikeAI(FirstNameLike);
        }
        else if (!String.IsNullOrEmpty(LastNameLike))
        {
            slbl = StudentListProcessor.FindStudentLastNameLikeAI(LastNameLike);
        }
        else if (!String.IsNullOrEmpty(StudentIdLike))
        {
            slbl = StudentListProcessor.FindStudentStudentIdLikeAI(StudentIdLike);
        }

        if (slbl.Count > 0)
        {
            lbl.Visible = false;
            BindData(slbl);
        }
        else if ((slbl.Count > 0) && (String.IsNullOrEmpty(UpdateSuccessful)))
            lbl.Visible = true;
    }

    protected void BindData(StudentListBaseList slbl)
    {
        gdvAthleteInfo.Columns[2].Visible = false;
        pnlNoRecordsFound.Visible = false;

        int pageSize = gdvAthleteInfo.PageSize;
        int currentPage = gdvAthleteInfo.PageIndex;
        int lastPage = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(slbl.Count / gdvAthleteInfo.PageSize)));
        int maxCount = ((currentPage + 1) * gdvAthleteInfo.PageSize);
        if (maxCount > slbl.Count) maxCount = slbl.Count;

        gdvAthleteInfo.DataSource = slbl;
        gdvAthleteInfo.DataBind();

        ContentPlaceHolder cph = new ContentPlaceHolder();
        Label lbl = new Label();
        cph = (ContentPlaceHolder)this.Page.Master.FindControl("MainContent");
        lbl = (Label)cph.FindControl("lblnoRecsFound");

        if (slbl.Count > 0)
        {
            LinkButton prevLinkButton = (LinkButton)gdvAthleteInfo.BottomPagerRow.FindControl("PreviousLinkButton") as LinkButton;
            LinkButton nextLinkButton = (LinkButton)gdvAthleteInfo.BottomPagerRow.FindControl("NextLinkButton") as LinkButton;
            Label pageDescriptionLabel = (Label)gdvAthleteInfo.BottomPagerRow.FindControl("PageDescriptionLabel") as Label;

            prevLinkButton.Text = "< prev " + pageSize.ToString();
            nextLinkButton.Text = "next " + pageSize.ToString() + " >";


            prevLinkButton.Enabled = (currentPage > 0);
            nextLinkButton.Enabled = (currentPage < lastPage);
            pageDescriptionLabel.Text = String.Format("{0} to {1} of {2}", (currentPage * pageSize) + 1, maxCount, slbl.Count);

        }

    }

    protected void gdvAthleteInfo_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditStudentInfo")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            int rowNum = Convert.ToInt32(e.CommandArgument);

            StudentListBase slb = new StudentListBase();

            Label lblAthleteInfoUid = (Label)row.FindControl("lblAthleteInfoRecordID");
            Label lblAthleteUid = (Label)row.FindControl("lblAthleteUid");
            TextBox tbxAthleteSSN = (TextBox)row.FindControl("tbxAthleteSSN");
            TextBox tbxAthleteLastName = (TextBox)row.FindControl("tbxAthleteLastName");
            TextBox tbxAthleteFirstName = (TextBox)row.FindControl("tbxAthleteFirstName");
            TextBox tbxAthleteName = (TextBox)row.FindControl("tbxAthleteName");
            Label lblSemesterTime = (Label)row.FindControl("lblSemesterTime");
            Label lblSemesterTotal = (Label)row.FindControl("lblSemesterTotal");
            TextBox tbxWarningCount = (TextBox)row.FindControl("tbxWarningCount");
            TextBox tbxNotes = (TextBox)row.FindControl("tbxNotes");
            Label lblWeekTotalMinutes = (Label)row.FindControl("lblWeekTotalMinutes");
            Label lblWeekTotal = (Label)row.FindControl("lblWeekTotal");
            TextBox tbxRequiredHours = (TextBox)row.FindControl("tbxRequiredHours");
            Label lblBankedTime = (Label)row.FindControl("lblBankedTime");
            Label lblBankedMinutes = (Label)row.FindControl("lblBankedMinutes");
            TextBox tbxsportID = (TextBox)row.FindControl("tbxsportID");
            DropDownList ddlSportTeam = (DropDownList)row.FindControl("ddlSportTeam");
            RadioButton rbtnSignedIn = (RadioButton)row.FindControl("rbtnSignedIn");
            Label lblUsedBankedMinutes = (Label)row.FindControl("lblUsedBankedMinutes");
            TextBox tbxGPA = (TextBox)row.FindControl("tbxGPA");
            TextBox tbxMajor = (TextBox)row.FindControl("tbxMajor");
            RadioButton rbtnActive = (RadioButton)row.FindControl("rbtnActive");
            TextBox tbxClassification = (TextBox)row.FindControl("tbxClassification");
            TextBox tbxStartTerm = (TextBox)row.FindControl("tbxStartTerm");
            //DropDownList ddlSportTeam = (DropDownList)row.FindControl("ddlSportTeam");

            slb.AthleteInfoUid = Convert.ToInt32(lblAthleteInfoUid.Text);
            slb.AthleteUid = lblAthleteUid.Text;
            slb.AthleteSSN = tbxAthleteSSN.Text;
            slb.LastName = tbxAthleteLastName.Text;
            slb.FirstName = tbxAthleteFirstName.Text;
            slb.AthleteName = tbxAthleteName.Text;
            slb.SemesterTotal = Convert.ToInt32(lblSemesterTotal.Text);
            slb.SemesterTime = lblSemesterTime.Text;
            slb.WarningCount = Convert.ToInt32(tbxWarningCount.Text);
            slb.Notes = tbxNotes.Text;
            slb.WeekTotal = lblWeekTotal.Text;
            //slb.RequiredHours = Convert.ToInt32(tbxRequiredHours.Text);
            slb.RequiredHours = Convert.ToDecimal(tbxRequiredHours.Text);
            slb.BankedMinutes = Convert.ToInt32(lblBankedMinutes.Text);
            slb.BankedTime = lblBankedTime.Text;
            slb.SportUid = ddlSportTeam.SelectedIndex;
            slb.TotalMinutes = Convert.ToInt32(lblWeekTotalMinutes.Text);
            slb.SignedIn = rbtnSignedIn.Checked;
            slb.UsedBankedMinutes = Convert.ToInt32(lblUsedBankedMinutes.Text);
            slb.GPA = tbxGPA.Text;
            slb.Major = tbxMajor.Text;
            slb.Active = rbtnActive.Checked;
            slb.Classification = tbxClassification.Text;
            slb.StartTerm = tbxStartTerm.Text;

            StudentListProcessor.UpdateStudentInfoAIUID(slb, slb.AthleteInfoUid);

            if (String.Compare(AccessLevel, "QUSuperMan") == 0)
                Response.Redirect("AddEditStudent.aspx?AccessLevel=QUSuperMan&UpdateSuccessful=yes", true);
            else
                Response.Redirect("AddEditStudent.aspx?UpdateSuccessful=yes", true);
        }
    }

    protected void gdvAthleteInfo_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdvAthleteInfo.PageIndex = e.NewPageIndex;
        BindData();

        return;
    }

    protected void gdvAthleteInfo_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlSportTeam = e.Row.FindControl("ddlSportTeam") as DropDownList;
            Label lblSportTeam = e.Row.FindControl("lblSportTeam") as Label;
            TextBox tbxsportID = e.Row.FindControl("tbxsportID") as TextBox;

            int sportID = Convert.ToInt32(tbxsportID.Text.ToString());
            ddlSportTeam.DataTextField = "ItemText";
            ddlSportTeam.DataValueField = "ItemValue";
            ddlSportTeam.DataSource = CommonUIProcessor.GetSportTeams();
            ddlSportTeam.DataBind();

            ddlSportTeam.SelectedIndex = Convert.ToInt32(tbxsportID.Text.ToString());
        }
    }

}

Open in new window




STUFF THAT WORKS
ASP page that has a working OnPageIndexChanging event
-------------------------------------------------------------------------------------------

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AllStudentsList.ascx.cs"
    Inherits="UserControls_AllStudentsList" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
<asp:UpdatePanel runat="server" ID="upStudentLoginGrid" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gdvAllStudentInfo" runat="server" AutoGenerateColumns="false" CssClass="SignedInGrid"
            GridLines="None" AllowSorting="true" AllowPaging="true" PageSize="10" PageIndex="0"
            DataKeyNames="AthleteInfoUid" PagerStyle-HorizontalAlign="Center" OnRowDataBound="gdvAllStudentInfo_OnRowDataBound"
            OnRowCommand="gdvAllStudentInfo_OnRowCommand" OnPageIndexChanging="gdvAllStudentInfo_OnPageIndexChanging">
            <Columns>
                <asp:TemplateField HeaderText="Student ID" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentUid" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteUID") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Student Name" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentName" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("AthleteName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <%--<asp:TemplateField HeaderText="Sport / Team" ItemStyle-CssClass="StudentName" Visible="false">
                    <ItemTemplate>
                        <asp:Label ID="lblSportTeam" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("SportUid") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>--%>
                <asp:TemplateField HeaderText="Required Hours" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                        <asp:Label ID="lblRequiredHours" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("RequiredHours") %>'></asp:Label>
                        <%--<asp:TextBox ID="TextBox1" runat="server" CssClass="StudentNameLabel" Text='<%# Eval("RequiredHours") %>'></asp:TextBox>--%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Sport / Team" ItemStyle-CssClass="StudentName">
                    <ItemTemplate>
                    <asp:Label ID="lblSportTeam" runat="server" CssClass="StudentNameLabel"  Enabled="false" Text='<%# Eval("SportUid") %>'></asp:Label>
                    <%--<asp:TextBox ID="tbxSportID" runat="server" CssClass="StudentNameLabel"  Enabled="false" Text='<%# Eval("SportUid") %>'></asp:TextBox>--%>
                        <asp:DropDownList runat="server" ID="ddlSportTeam" Width="210px" Visible="false">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <%--<asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lkbtnDeleteStudentRecord" Text="Delete Student"
                            CommandName="DeleteStudentRecord" CommandArgument='<%# Eval("AthleteUid") %>'
                            CssClass="button small green" />
                        <asp:LinkButton runat="server" ID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            Text="Delete this record" CommandName="DeleteStudentRecord" CommandArgument='<%# Eval("AthleteUid") %>'
                            CssClass="button small green" Visible="false" />
                        <act:ModalPopupExtender ID="deleteModalPopupExtender" runat="server" CancelControlID="btnCancel"
                            OkControlID="btnDelete" TargetControlID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            PopupControlID="divDeleteConfirmation" BackgroundCssClass="modalBackground" />
                        <act:ConfirmButtonExtender ID="deleteConfirmButtonExtender" runat="server" TargetControlID="theDummyButtonAsAPlaceHolderForTheModelPopupExtender"
                            Enabled="True" DisplayModalPopupID="deleteModalPopupExtender" />
                    </ItemTemplate>
                </asp:TemplateField>--%>
                <%--<asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton runat="server" ID="lkbtnSaveChanges" Text="Save Changes" CommandName="SaveChanges"
                            CommandArgument='<%# Eval("AthleteUid") %>' CssClass="button small green" />
                    </ItemTemplate>
                </asp:TemplateField>--%>
            </Columns>
            <PagerSettings Mode="NextPrevious" />
            <PagerStyle CssClass="Paging" />
            <PagerTemplate>
                <div class="Paging">
                    <asp:LinkButton ID="PreviousLinkButton" runat="server" CommandArgument="Prev" CommandName="Page"
                        CssClass="PagerControl" Text="Prev"></asp:LinkButton>
                    <asp:Label ID="PageDescriptionLabel" runat="server" CssClass="PagerControl"></asp:Label>
                    <asp:LinkButton ID="NextLinkButton" runat="server" CommandArgument="Next" CommandName="Page"
                        CssClass="PagerControl" Text="Next"></asp:LinkButton>
                </div>
            </PagerTemplate>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:Panel runat="server" ID="pnlSignInOut">
    <div class="AddrdssBookContent UserProfile clearfix">
        <div id="divDeleteConfirmation" runat="server" align="center" class="confirmDelete"
            style="display: none">
            <div class="clearfix">
                <div class="inner">
                    <h4>
                        <asp:Label runat="server" ID="lblPasswordPrompt" Text="This will delete all information including sign in and out records for this student!"></asp:Label></h4>
                </div>
                <div class="Buttons">
                    <asp:Button ID="btnSignIn" CssClass="button small" runat="server" Text="Continue"
                        OnClick="btnSignIn_click" Style="margin-left: 15px;" />
                    <asp:Button ID="Button1" CssClass="button small" runat="server" Text="Cancel" />
                </div>
                <asp:Label runat="server" ID="lblInvalidPassword" Visible="false"></asp:Label>
            </div>
        </div>
    </div>
</asp:Panel>
<div class="updateAlert">
    <asp:Panel runat="server" ID="pnlNoRecordsFound" Visible="false" CssClass="UpdatedMessage Alert SavedSmall">
        <h3>
            No records found.</h3>
    </asp:Panel>
</div>

Open in new window


C# for ASP page that has working OnPageIndexChanging event
----------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudyTimeTracker.Common.Domain;
using StudyTimeTracker.Public.Business;

public partial class UserControls_AllStudentsList : System.Web.UI.UserControl
{
    private string _pullStudents;

    public static class myGlobalVars
    {
        public static string studentID;
    }

    public String SidSname
    {
        get
        {
            return Request.QueryString["SidSname"];
        }
    }

    public String FullNameLike
    {
        get
        {
            return Request.QueryString["FullNameLike"];
        }
    }

    public String FirstNameLike
    {
        get
        {
            return Request.QueryString["FirstNameLike"];
        }
    }

    public String LastNameLike
    {
        get
        {
            return Request.QueryString["LastNameLike"];
        }
    }

    public String StudentIdLike
    {
        get
        {
            return Request.QueryString["StudentIdLike"];
        }
    }

    public String AccessLevel
    {
        get
        {
            return Request.QueryString["AccessLevel"];
        }
    }

    public String ShowAllStudents
    {
        get
        {
            return Request.QueryString["ShowAllStudents"];
        }
    }

    public String PullStudents
    {
        get
        {
            return Request.QueryString["PullStudents"];
            
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
    }

    protected void gdvAllStudentInfo_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlSportTeam = e.Row.FindControl("ddlSportTeam") as DropDownList;
            Label lblSportTeam = e.Row.FindControl("lblSportTeam") as Label;
            TextBox lblSportID = e.Row.FindControl("lblSportID") as TextBox;

            ddlSportTeam.DataTextField = "ItemText";
            ddlSportTeam.DataValueField = "ItemValue";
            ddlSportTeam.DataSource = CommonUIProcessor.GetSportTeams();
            ddlSportTeam.DataBind();

            ddlSportTeam.SelectedIndex = Convert.ToInt32(lblSportTeam.Text);

            lblSportTeam.Text = Utility.GetSportTeamNameByID(Convert.ToInt32(lblSportTeam.Text));

        }
    }

    protected void gdvAllStudentInfo_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteStudentRecord")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            //int athleteuid = Convert.ToInt32(e.CommandArgument);
            myGlobalVars.studentID = e.CommandArgument.ToString();

            //divDeleteConfirmation.Visible = true;
            AjaxControlToolkit.ModalPopupExtender deleteModalPopupExtender = (AjaxControlToolkit.ModalPopupExtender)row.FindControl("deleteModalPopupExtender");

            deleteModalPopupExtender.Show();
            //Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&DeleteStudent={1}", AccessLevel, athleteuid.ToString()));                  
        }
        else if (e.CommandName == "SaveChanges")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            string athleteuid = e.CommandArgument.ToString();

            TextBox tbxRequiredHours = (TextBox)row.FindControl("tbxRequiredHours");
            DropDownList ddlSportTeam = (DropDownList)row.FindControl("ddlSportTeam");

            if (Utility.UpdateStudentInfoFromAllStudentsGrid(athleteuid, tbxRequiredHours.Text.ToString(), ddlSportTeam.SelectedIndex))
                Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&SuccessfulUpdate=yes", AccessLevel, athleteuid.ToString()));
            else
                Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&SuccessfulUpdate=no", AccessLevel, athleteuid.ToString()));
        }

    }

    //private void InitializePageControls()
    //{
    //    ddlSportTeam.DataTextField = "ItemText";
    //    ddlSportTeam.DataValueField = "ItemValue";
    //    ddlSportTeam.DataSource = CommonUIProcessor.GetSportTeams();
    //    ddlSportTeam.DataBind();
    //}

    protected void BindData()
    {
        StudentListBaseList slbl = new StudentListBaseList();
        ContentPlaceHolder cph = new ContentPlaceHolder();
        Label lbl = new Label();
        cph = (ContentPlaceHolder)this.Page.Master.FindControl("MainContent");
        lbl = (Label)cph.FindControl("lblnoRecsFound");

        if (ShowAllStudents == "Yes")
        {
            slbl = StudentListProcessor.GetAllStudents();
        }
        else if (PullStudents == "PullStudents")
        {
            slbl = Utility.LoadCreightonStudents();
        }

        if (!String.IsNullOrEmpty(FullNameLike))
        {
            slbl = StudentListProcessor.FindStudentFullNameLikeAI(FullNameLike);
        }
        else if (!String.IsNullOrEmpty(FirstNameLike))
        {
            slbl = StudentListProcessor.FindStudentFirstNameLikeAI(FirstNameLike);
        }
        else if (!String.IsNullOrEmpty(LastNameLike))
        {
            slbl = StudentListProcessor.FindStudentLastNameLikeAI(LastNameLike);
        }
        else if (!String.IsNullOrEmpty(StudentIdLike))
        {
            slbl = StudentListProcessor.FindStudentStudentIdLikeAI(StudentIdLike);
        }

        if (slbl.Count > 0)
        {
            lbl.Visible = false;
            BindData(slbl);
        }
    }

    protected void BindData(StudentListBaseList slbl)
    {
        //gdvAllStudentInfo.Columns[2].Visible = false;
        pnlNoRecordsFound.Visible = false;

        int pageSize = gdvAllStudentInfo.PageSize;
        int currentPage = gdvAllStudentInfo.PageIndex;
        int lastPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(slbl.Count / gdvAllStudentInfo.PageSize)));
        int maxCount = ((currentPage + 1) * gdvAllStudentInfo.PageSize);
        if (maxCount > slbl.Count) maxCount = slbl.Count;

        gdvAllStudentInfo.DataSource = slbl;
        gdvAllStudentInfo.DataBind();

        if (slbl.Count > 0)
        {
            LinkButton prevLinkButton = (LinkButton)gdvAllStudentInfo.BottomPagerRow.FindControl("PreviousLinkButton") as LinkButton;
            LinkButton nextLinkButton = (LinkButton)gdvAllStudentInfo.BottomPagerRow.FindControl("NextLinkButton") as LinkButton;
            Label pageDescriptionLabel = (Label)gdvAllStudentInfo.BottomPagerRow.FindControl("PageDescriptionLabel") as Label;

            prevLinkButton.Text = "< prev " + pageSize.ToString();
            nextLinkButton.Text = "next " + pageSize.ToString() + " >";


            prevLinkButton.Enabled = (currentPage > 0);
            nextLinkButton.Enabled = (currentPage < lastPage);
            pageDescriptionLabel.Text = String.Format("{0} to {1} of {2}", (currentPage * pageSize) + 1, maxCount, slbl.Count);

        }

    }

    protected void gdvAllStudentInfo_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gdvAllStudentInfo.PageIndex = e.NewPageIndex;
        BindData();

        return;
    }

    protected void btnSignIn_click(object sender, EventArgs e)
    {
        string studentName = Utility.GetStudentNameByID(myGlobalVars.studentID);
        bool bDeleteConf = Utility.DeleteStudentRecord(myGlobalVars.studentID);

        if (bDeleteConf)
            Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&DeletedStudent={1}", AccessLevel, studentName));
        else
            Response.Redirect(String.Format("AddEditStudent.aspx?AccessLevel={0}&ShowAllStudents=Yes&DeletedStudent=Fail", AccessLevel));
        //lblConfirmationMsg.Text = "All of this student's data has been deleted!";
        //pnlUpdateConfirmation.Visible = true;
    }
}

Open in new window

0
Comment
Question by:mikesExpertExchange
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 38815667
Hi

As you have taken update panel with update mode as conditional then you have to manually update that update panel which contains gridview.

Try using

upAthleteInfoPanel.Update();
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38815696
@mroonal: Where do I put that line of code? In what event? Also, my other panel in the ASP page where I'm not having this problem is also set to conditional, so why would it work in one panel but not the other?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38815759
@mike,
Is it the page not updating issue or it's the event itself not hit if you set a breakpoint while debugging?

First thing I would make sure is it is at least making a PostBack. Set a breakpoint in your PageLoad.
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38815789
@guru_sami: it's not hitting the event at all. I've set a break point in the other page and it actually hits the event. but let me make sure it is hitting the post back code correctly.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38815873
@guru_sami: you are right about one thing that I guess I have to try to figure out. In the form that I'm NOT having trouble with, in the PageLoad, it is doing a post back so it works. In the page with the problem there is no postback occuring so it's binding the data again.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38815910
Make sure there aren't any validation or javascript errors. Most of the time they prevent postback.
0
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38815949
@guru_sami: I do seem to get a javascript error but i get it on both the page that it works on and the page that it doesn't work. So I'm confused and not very good at debugging javascript errors in either case.

 validDomain: function(){
try{
var d = document;
if( d == null || d.domain == null ||
d == undefined || d.domain == undefined || d.domain == ""

|| d.location == "about:blank" || d.location == "about:Tabs" <--error here???

|| d.location.toString().indexOf( "superfish.com/congratulation.jsp" ) > -1 ){
return false;
}else{
return (/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,5}$/).test( d.domain );
}
}catch(e){
return false;
}
}
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816708
What's the error and where's the function defined?
If it's working on other page then that error might not be really interfering in postback but something else.

What you can try is create a new sample page and add one thing at a time and see when it starts breaking.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now