.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Pager Findcontrol

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
 Hi, I use a pager to navigate a listview<asp:DataPager ID="Pager" runat="server" PagedControlID="Listview1" PageSize="6"> <Fields> <asp:TemplatePagerField> <PagerTemplate> <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# IIf(Container.TotalRowCount>0, (Container.StartRowIndex / Container.PageSize) + 1 , 0) %>" /> <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" /> <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" /> </td><td class="tdPager"></td><td> </PagerTemplate> </asp:TemplatePagerField> <asp:NextPreviousPagerField ShowFirstPageButton ="true" ShowNextPageButton="true" ShowPreviousPageButton="true" ShowLastPageButton="true" ButtonType="Button" ButtonCssClass="Navigator" FirstPageText="|<" LastPageText=">|" NextPageText=">" PreviousPageText="<" /> </Fields> </asp:DataPager>  <asp:Label ID="lbl1" runat=&q

View Complete Post

More Related Resource Links


I have 2 web pages. First page has a textbox and a button control.

when I enter test and click on the button , system goes to the second page. And in the second page I want to access the Textbox in the first page. When I try to do this I get the following error.

"Object reference not set to an instance of an object. Following is my code :

Dim txt As New TextBox

' Find the server name on the previous page
txt = CType(Page.PreviousPage.FindControl("TextBox2"), TextBox)
If Not IsNothing(txt) Then
Response.Write("[Name Not available]")
End If

I know I could do this with session, but I want to use the Page.PreviousPage.FindControl. Any help is greatly appreciated

Collaboration Data Objects: Send Microsoft Exchange Appointment Reminders to Your Pager Using CDO


Besides your typical e-mail services, Microsoft Exchange also provides the service infrastructure you need to build extensible knowledge and workflow management systems. Understanding Collaboration Data Objects (CDO) is the key to accessing these Exchange services for your own programs. With CDO you can automate tedious tasks and integrate information such as e-mail, calendars, and contacts with almost any application. This article explains how CDO enables you to access Exchange services, then walks you through a sample application that reads calendar events from an Exchange server and sends pager reminders to your users.

Sean McCormick

MSDN Magazine June 2000

Page.FindControl Causing Null Reference Exception


Hi guys,

I developed a page in VWD 2008 and it works perfectly locally, but when I deployed it on the server every Page.FindControl() call is causing the NullReference Exception "Object reference not set to an instance of an object. " Can anyone help me out? Code is below


Mike Marshall

            For i As Integer = 1 To 10
                If (CType(Page.FindControl("last_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("first_" & i), TextBox).Text.Length > 0) Or (CType(Page.FindControl("dob_" & i), TextBox).Text.Length > 0) Then
                    Dim person_entry(7) As String
                    person_entry(0) = info_list.Count - 1
                    person_entry(1) = CType(Page.FindControl("last_" & i), TextBox).Text
                    person_entry(2) = CType(Page.FindControl("first_" & i), TextBox).Text
                    person_entry(3) = CType(Page.FindControl("dob_" & i), TextBox).Text
                    person_entry(4) = CType(Page.FindControl("appear_" & i), TextBox).Text
                    person_entry(5) = CType(Page.FindControl("mental_" & i), TextBox).Text
                    person_entry(6) = CType(Page.FindControl("behave_" & i), TextB

GridView EmptyDataTemplate and FindControl Method


I have 2 textboxes, a dropdownlist and a button in the EmptyDataTemplate of a GridView control and when I click the button I want to get the text from the text boxes and DropDownList put it in the QueryString of a URL i redirect to, but I can't work out why the FindControl method cannot find the controls.  I am using the following code:

Dim ddlNumPpl As DropDownList = GridView1.FindControl("ddlNumPpl")

I get an "Object reference not set to an instance of an object" error though when I try to refer to the SelectedValue property of it though.  I would be very grateful if someone could let me know why the FindControl method can't find the control and what I should do to rectify it.

Many Thanks (in advance),


Nested controls in UserControl return null (FindControl)

Hi everyone, I have a very weird issue. I have a UserControl that has some controls inside. I want to refer those controls after, in another postback. But when I try to get them the ".Controls" property of my controls returns null. I'm working on vs2008 Here is the sample code: public partial class MyUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { foreach (Control control in this.Controls) { Response.Write(control.ClientID); } } private void MyTable() { Table table = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); CheckBox check = new CheckBox(); check.ID = "theId"; check.Text = "My Check"; check.AutoPostBack = true; cell.Controls.Add(check); row.Cells.Add(cell); check = new CheckBox(); check.ID = "theOther"; check.AutoPostBack = true; check.Text = "My Other Check"; cell = new TableCell(); cell.Controls.Add(check); row.Cells.Add(cell); table.Rows.Add(row); this.Controls.Add(table); } protected override void Render(HtmlTextWriter writer) { MyTable(); base.Render(writer); } } And in the Default.aspx is like:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.cs" Inherits="Tester.Default" %> &

Using FindControl on Nested FormViews

I have a nested FormView and I need to get the Text values from some of its xontrols (TextBox) in code behind. I can easily pull the values from the "parent" FormView using: TextBox txtBox = (TextBox)fvParent.FindControl("txtField");String myStr= txtBox.Text; Although, when I try to get a refence to one of the controls in the "child" FormView I get a null. I am trying to do this: FormView formView = (FormView)fvParent.FindControl("fvChild");TextBox txtBox = (TextBox)fvChild.FindControl("txtChildField");String myStr= txtBox.Text; The variable "formView" is set to null. Can the FindControl method not find nested items? If not, what is the proper way of getting the values from these fields (in the Child/Nested FormView)?   Thanks again for everyone's help!  

LoginView.FindControl not finding control

I'm trying to bind data to a repeater. The repeater is inside a loginView control. Like so:            <asp:loginview id="loginView" runat="server">                <anonymoustemplate>                    <asp:repeater id="rpLessons" runat="server">                                            <itemtemplate>                            <div>                                <a  href="Default.aspx?lid=<%# Eval("PodID") %>"><%# Eval("Name") %></a><%#Eval("Duration")%>                            </div>                        </itemtemplate>    &n

GridView Pager not showing proper number of rows

I have created an out-of-the-box  (default everything) ASP.NET Dynamic Data Entities Web Site using VS2010, C# and the .NET Framework 4. Created an ADO.NET Entity Data Model based off a MS SQL 2008 R2 database and registered that EF data model for my dynamic data. Everything works great except for the one change I would like to make. By default, the GridViewPager.ascx file provides the values 5, 10, 15 and 20 in the dropdown for GridView's "Results per page" option. I would like to change that to 10, 20, 30 and 40 - with 40 being the default selected option. I went to the code behind file and modified it to have the values I am wanting. Those values now show in the dropdown, and work if I select them. Problem: when the page is first rendered only 10 rows will show. How can I change this? Any help would be greatly appreciated.   Thanks

Div in LoginView findcontrol

Hi,This code works:<div id="GridDiv" runat="server">               gridview would go in here....           </div>GridDiv.Visible=false;However, because I have a Div in LoginView2 I have to find with findcontrol.This is not work:        LoginView Div = LoginView2.FindControl("GridDiv") as LoginView;        Div.Visible = false; Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: Line 785: Line 786: Line 787: Div.Visible = false; Thanks for your help!

FindControl returns null

I am trying to fetch two Labels within a Repeater element to attach data to; which Label is assigned which Data Field depends on the result of a Radio Button List, hence why I need to fetch them in the code behind. This is the ASP.NET code: <asp:View ID="vwSportType" runat="server"> <table> <tr> <td rowspan="2"> <span class="boldtext">Select type of sport:</span><br /><br /> <asp:ListBox ID="lbType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="lbType_OnSelectedIndexChanged" Height="300px" Width="12em"> </asp:ListBox> </td> <td width="70%"> <span class="boldtext">Show by: <asp:RadioButtonList ID="rbSportType" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Text="Date, Sport" Selected="True" Value="0"></asp:ListItem> <asp:ListItem Text="Sport,

findControl ?

Hi to access an aspx drop down control inside a user control?

function - findcontrol

How to write a function that should always be identified:RadioButton LoginView2.FindControl RadioButton22 = ("RadioButton2") as RadioButton;Currently, I always write in any event: RadioButton LoginView2.FindControl RadioButton22 = ("RadioButton2") as RadioButton;Is it possible how to write a function that would be written once and used repeatedly?And how do you call?thanks.

findcontrol problem in a gridview

Hey guys I've got a gridview with a few textboxes in each row which I want to insert into a database, after a user clicks a submit button (thats outside of the gridview)  This is my code for the gridview<asp:GridView ID="GridView2" AutoGenerateColumns="false" runat="server" EnableModelValidation="True"> <Columns> <asp:TemplateField > <ItemTemplate> name: <asp:Label ID="Label12" runat="server" Text='<%# Bind("PlayN") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="TxtFirst" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="txtLast" runat="server"></asp:TextBox> </ItemTemplate>

FindControl TextBox

Hi all, I have one page text.aspx there is textbox control <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <% Dim mf As New MyClass mf.filltxt() %>I am trying to call filltxt from MyClass via below code. but it seems code is unable to find the control. Public Sub filltxt() Dim txtb As TextBox = CType(Page.FindControl("TextBox1"), TextBox) txtb.Text = "hello world" End SubI am getting Error : Object reference not set to an instance of an object.I will appreciate if you guys correct my code.Thank You

Missing pager when using PagedDataSource in GridView

When I use a pageddatasource as datasource for the gridview and set the virtualitemcount greater than the pagesize (example: 54) the pager does not become visible. I think this is a bug in the gridview control. Can someone help me????? I'm really confused....   code:   public partial class DatagridWithCustomPaging : System.Web.UI.Page{      protected void Page_Load(object sender, EventArgs e)      {         if (!IsPostBack)         {            PagedDataSource pagedDataSource = new PagedDataSource();            pagedDataSource.AllowServerPaging = true;            pagedDataSource.AllowPaging = true;            pagedDataSource.DataSource = LoadData();            pagedDataSource.VirtualCount = 440;            GridView1.DataSource = pagedDataSource;            GridView1.DataBind();         }    &nbs

Gridview Pager does not appear


Hi all


I wonder if anyone has a solution to this. I have a manually bound gridview. I have enabled paging and have set the page size. However my pager numbers do not appear for some reason.


Any ideas 

GridView go to top of page when page is changed using bottom pager


I have a grid view where the user can change pages at either the top or the bottom of the grid view. 

I want the view to go back to the top whenever a user changes the page, whether they are changing from the top or the bottom.  I've tried using anchors and javascript to achieve this but it does not work.  The javascript is executed and the user is taken to the top of the gridview, this can be seen by placing an alert after the javascript to change the view.  But the last thing that happens on the page change is that the window is returned to it's previous position (the bottom of the page).  Is there any way of doing this?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend