1

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.

2
  • Dear you have specified updatemode to conditional. Do you have mentioned postback trigger to your update panel ???? Jul 31, 2012 at 10:22
  • Ok - with StudentListDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); in StudentListView_PagePropertiesChanging() event, the datapager now works fine, but still the problem of update panel stands as daemon, which causes full postback, and i lose all my javascript local variable.
    – j4m4l
    Jul 31, 2012 at 11:01

2 Answers 2

0

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.

14
  • PagePropertiesChanging event is associated with ListView and not with DataPager, also i have removed UpdateMode and tried but its still not working..
    – j4m4l
    Jul 31, 2012 at 10:30
  • sorry I give wrong ID to trigger. Your code works normal without update panel ???? Check it Jul 31, 2012 at 10:34
  • sorry, but what you suggest is not working it is still giving full postback.
    – j4m4l
    Jul 31, 2012 at 10:35
  • of course it will work normal without updatepanel, but i want to use update panel for ajax functionality.
    – j4m4l
    Jul 31, 2012 at 10:37
  • both the approcah are correct - setting DataSourceId in markup or setting DataSource in code behind, but datapager is causing full postback, that is why i tried the apprach of code behind ( as read about it in some article )
    – j4m4l
    Jul 31, 2012 at 10:58
-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.