Question

When i change the page in datapager it causes full postback, even the datapager is working very abnormally, idont know what is the reason. by abnormaaly i mean sometime data is shown sometime doesnt,
Following is th my code in c#

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

    protected void StudentListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        BindListView();
    }
    private void BindListView()
    {
        StudentListView.DataSource = StudentDataSource;
        StudentListView.DataBind();
    }

    protected void StudentDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.Arguments.MaximumRows = StudentListDataPager.MaximumRows;
        e.Arguments.StartRowIndex = StudentListDataPager.StartRowIndex;
    }

Following is my markup

    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
    <ContentTemplate>        <
    <asp:DropDownList runat="server" ID="BatchDropDownList" AutoPostBack="True">
        <asp:ListItem Text="Batch 1" Value="1" Selected="True" />
        <asp:ListItem Text="Batch 2" Value="2" />
    </asp:DropDownList>

    <asp:ListView ID="StudentListView" runat="server"       
        ItemPlaceholderID="ListViewContent" 
            EnableViewState="false" 
            onpagepropertieschanging="StudentListView_PagePropertiesChanging"> 
        <LayoutTemplate> 
            <table style="width:100%">
                <thead>
                    <tr>
                        <th class="align-left"><strong>Name</strong></th>
                        <th class="align-left"><strong>MobNo</strong></th>
                    </tr>
                </thead>
                <tbody runat="server" id="ListViewContent"> 
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="3">

                        </td>
                    </tr>
                </tfoot>
            </table>

        </LayoutTemplate>  
        <ItemTemplate>  

            <tr>
                <td style="width:70%;"><%# Eval("FirstName") %>&nbsp<%# Eval("LastName") %></td>
                <td style="width:30%;"><%# Eval("MobNo") %></td>                    
            </tr>

        </ItemTemplate>             
    </asp:ListView>
    <asp:DataPager ID="StudentListDataPager" runat="server" PageSize="5" PagedControlID="StudentListView">
        <Fields>
            <asp:NumericPagerField />
        </Fields>
    </asp:DataPager>


    <asp:ObjectDataSource ID="StudentDataSource" runat="server" 
        SelectMethod="GetStudentListBatchWise" SelectCountMethod="StudentCount" 
            TypeName="SCERPCommonUtil.Student" EnablePaging="True" 
            onselecting="StudentDataSource_Selecting">
        <SelectParameters>
            <asp:ControlParameter Name="batchId" ControlID="BatchDropDownList" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:ObjectDataSource>
    </ContentTemplate>
</asp:UpdatePanel>

Please tell me if i am making any mistakes.

P.S. : Please dont point me to any stackoverflow question as i have read all of them, and none is specific to my requirement,

Most important problem i am facing is that datapager is giving full postback, even if put datapager inside updatepanel same thing happens.

Was it helpful?

Solution 2

I figured it - incase somebody come looking -

i was using <form runat="server">...<form> tag, inside which all this listview,datapager code was present. When i assigned unique id attribute to form tag then everything started working correctly.
Although i dont understand the reason of such behavior.

OTHER TIPS

Dear you have specified updatemode to conditional.But you have mentioned any trigger to your update panel. Add the AsyncPostBackTrigger to your update panel

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate> 
<Triggers>
            <asp:AsyncPostBackTrigger ControlID="StudentListView" EventName="PagePropertiesChanging" />
</Triggers>
<ContentTemplate>
</asp:UpdatePanel>

From MSDN: If the UpdateMode property is set to Conditional, and one of the following conditions occurs:

  1. You call the Update method of the UpdatePanel control explicitly.
  2. The postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. In this scenario, the control explicitly triggers an update of the panel content. The control can be either inside or outside the UpdatePanel control that defines the trigger.
  3. The ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. A child control of a nested UpdatePanel control does not cause an update to the outer UpdatePanel control unless it is explicitly defined as a trigger.

Updated Answer: why you have not mention DataSourceID attribute in your listview ???

 <asp:ListView ID="StudentListView" runat="server"  DataSourceID  ="StudentDataSource"

and you are binding your list view in your code behind as

private void BindListView()
{
    StudentListView.DataSource = StudentDataSource; //also it should be DataSourceID 
    StudentListView.DataBind();
}

you are using object data source and in your code you are binding it as a datasource which is wrong. Bind it as a datasource ID or simple mention the datasourceID attribute of listview then you don't have to bind it in your code behind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top