.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

Div in LoginView findcontrol

Posted By:      Posted Date: September 11, 2010    Points: 0   Category :ASP.Net
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!

View Complete Post

More Related Resource Links

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


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

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),


Create User Wizard and Loginview error


 When i place the create user wizard control inside the Loginview Anonymous Template, the Create User Wizard gives an error inside the C# file. Here is a snippet

Home.aspx Web Form

 <asp:LoginView ID="LoginView2" runat="server">
        <asp:CreateUserWizard ID="CreateUserWizard1" CreateUserButtonType="Image" 
        CreateUserButtonImageUrl="~/images/signup.png" cssclass="createuser" 
        runat="server" OnCreatedUser="CreateUserWizard1_CreatedUser" 
           <TextBoxStyle CssClass="Ctextbox" />
            <LabelStyle cssclass="lbl" />
                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" />
                <asp:CompleteWizardStep   ID="CompleteWizardStep1" runat="server" />
        news here

Here is the C# Code with the error 


loginview and Windows Authentication?

Can you use a loginview to hide a control (or set of controls) using WIndows Authentication?  All Ic an find are articles on Forms Authentication but I don't use that in my application.  Any other ideas on how to hide a control based on membership to an Active Directory group? 

Login contained within a LoginView Events firing?

Hi there,   I'm in the process of trying to figure out how to program in ASP.Net. My senario is this: (A) I've created a master Page (B) In The master page I have a Login Control that is contained in a LoginView control. I cannot figure out how to get the events to fire when it's in this sitution. Any help would be good. If the Login control is situated on it's own the events (LogginIn etc) will fire? 

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!  

How do i get the value of an embedded textbox in a loginview

hi guys,How do i get the value of an embedded textbox in a loginview ?I have a textbox, in a loginview1.How do i get the value of the textbox ?string user = Loginview1.Textbox1.Text ;thanksEhi

LoginView DropDownList

LoginView DropDownList4 = LoginView2.FindControl("DropDownList4") as LoginView;DropDownList4.SelectedValue = "abc";Why not find SelectedValue?What am I doing wrong?

LoginView Control Issue

I'm using VWD 2010 Express, and I'm working on a school lesson that I actually did approximately 2 years ago In VWD 2005 with no problems.  I am just learning to program, so my knowledge is very limited.The lesson walks me through creating a master page and then I created a page called "Login.aspx".  On the login page, I am dropping a LoginView control into the ContentPlaceHolder section, and then I'm supposed to type "Welcome !" into the LoginView box for the LoggedIn template, but the LoginView box is very small and when I start typing, the first couple of letters go into the LoginView box, and then they start showing up on the far left outside of the LoginView control.  When I try to click back in the LoginView window, it will only select the entire control, and I can no longer modify what's in the box (unless I go to Source view).  I can't even begin to explain how frustrating this is!!!  It's tough enough trying to learn this stuff and now my development tool is giving me grief!  I don't understand why it worked fine in VWD 2005, but not now (and I'm using the same exact lesson material).

LoginView, DropDownList, Cookie, AutoPostBack Conundrum

OK, I am at a complete loss. Users for my site can have many stores to configure under their one user account. When they login I have the app generate a cookie for each store and hold all the stores basic information. For each cookie I then generate a list item in a drop down list. I can get the list to generate just fine and all of the pages that reference the list get the information fine. When I change the list to a different item however, and the page posts back my first LoginView is set to LoggedInTemplate while my navigation loginview (in site.maser like the first one) and my content loginview (in the actual page) come back in AnonymousTemplate, even though the user is authenticated. I can either do a response.redirect or physically refresh the page and all loginviews are in LoggedInTemplate again. The problem is though that I lost all of the postback data so I can essentially only view information on the first item in the dropdownlist. Now, I am new to asp.net authentication, and while I feel that I am starting to get the hang of it, there is a very good chance that I am doing something wrong. I have all the authentication working correctly and except for this postback issue. I can login, navigate through pages that aren't accessible without being authenticated and I can logout without issue. If anyone has any suggestions it would be gr

DataList Within LoginView

I've a datalist within the logged in template. On the page_load first I'm ensuring the visitor is logged inIf User.Identity.IsAuthenticated Then Following that I'm just trying to populate the datalist... Dim myDataAdapter As SqlDataAdapter Dim strToday As String = DateTime.Today.ToString("dd MMM yyyy") conConnect = New SqlConnection(connstring) myDataAdapter= New SqlDataAdapter("SELECT command goes here FROM my table", conConnect) Dim ds As Data.DataSet = New Data.DataSet myDataAdapter.Fill(ds) Dim DataList1 As DataList = LoginView1.FindControl("DataList1") DataList1.DataSource = ds DataList1.DataBind() conConnect.Close()   However this doesn't work, I get the following error: Object reference not set to an instance of an object.... Highlighting: DataList1.DataSource = ds If I take the loginview away then it works, but I thought the loginview1.findcontrol part would solve any problems. I would appreciate any 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.
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