.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

LoginView.FindControl not finding control

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

View Complete Post

More Related Resource Links

Finding a control from a control collection



I'm trying to write a bit of code that will format all the numeric values in lables in my gridview. here's what i am doing right now:

On the RowDataBound Event, i create a row object for the row that is currently being bound.
then i go use the FindControl method to grab each label by name.

Problem is there's too many columns in this table and i really dont wnat to have to type it all out. Here's an example of what i am currently doing

' Get row being bound
Dim myRow = e.Row

' Get labes to be formatted
Dim lblMunicipalIncineration = CType(myRow.FindControl("lblMunicipalIncineration"), Label)

' format labels
If lblMunicipalIncineration IsNot Nothing Then
    If Not String.IsNullOrEmpty(lblMunicipalIncineration.Text) Then
        lblMunicipalIncineration.Text = FormatNumber(lblMunicipalIncineration.Text, 0, TriState.False, TriState.False, TriState.True)
    End If
End If

Can i use myRow.Controls to grab a list of all the controls and then somehow get a list of all labels in the collection and then use a for loop to go through and format each label?

Finding a WPF control by Name in a Panel

How can I loop through the controls collection of a WPF panel and find a control by name?  The StackPanel1.Children(0).Name property does not exist. I looking for a method equivelent to this WinForm code... Friend Function DBX_FindControlByName(ByRef objContainer As Object, _   ByVal strControlName As String, _   ByRef objFoundControl As Control) As Boolean   Dim objControl As Control = Nothing   If Not IsNothing(objFoundControl) Then Return True   Try   'objContainer must be a controls collection like Me.Controls   For Each objControl In CType(objContainer, Control.ControlCollection)   If objControl.Name.ToUpper = strControlName.ToUpper Then objFoundControl = objControl   Exit For   Else   If objControl.HasChildren Then   'This control has children so it must be a container DBX_FindControlByName(objControl.Controls, strControlName, objFoundControl)   End If   End If   Next   Return True   Catch ex As Exception strErrMsg = "DBX_FindControlByName." & objControl.Name & ": " & ex.Message   End Try   End Function Thanks. Mike

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

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!

Finding a control inside a ListView on a master page

I have a listview on a master page that ISN'T part of a content place holder that I want to fill in and disable if the user is already logged in. I have a label set up already which works fine. I'm just having problems accessing a Textbox by the name of "NameTextBox" in the InsertItem template of the listview.Here is the part of my codefile:Dim vCurrentUser As MembershipUser = Membership.GetUser() If Not vCurrentUser Is Nothing Then Dim pnl As Label = LoginView1.FindControl("Label1") pnl.Text = Page.User.Identity.Name Dim NameBox As TextBox = ListView1.InsertItem.FindControl("NameTextBox") NameBox.Text = Page.User.Identity.Name End IfI get a Object not found exception. What is the correct way to find a control inside a InsertItemTemplate and the correct Event to use?

Findcontrol returns an empty control


Hello all,

The concept of findcontrol seems to elude me somewhat and I would like some advice if anyone can spare it.

My SP page layout contains a richhtmlfield with a highly descriptive ID of "RichHtmlField1". The same page layout contains a custom user control that needs to read te contents of this richhtmlfield and e-mail it.

To get the content I figured I'd use the findcontrol function. And this works fine. I then cast the control to a richhtmlfield and try to access the .Html property. But apparently that's empty. I don't understand that, since if you look at the page the content of the field is clearly filled.

Can anybody shed some light on the subject?

My (highly professional) code:

HtmlGenericControl myDiv = new HtmlGenericControl("div");

Control cntlTest = this.Parent.FindControl("RichHtmlField1");

//This works and gives me the proper results
myDiv.InnerHtml += cntlTest.ID + " || " + cntlTest.GetType();

//This is empty
myDiv.InnerHtml += 

Finding UserControls within a PlaceHolder control



I am having problems finding my UserControls inside the Controls collection of a Placeholder control.  

I have a ListView control with a PlaceHolder control in its ItemTemplate. OnItemdataBound for the ListView control I am adding a custom UserControl to the Controls collection of the Placeholder control. It all renders fine. My problem is when I try to find my user controls in the Placeholder. I just can't get it back. My code is below.

My objective here is to get to the input controls within my UserControl and call the save method of this. Please help.

PlaceHolder intakeBenefitHolder = null;
protected void lvIntakeBenefits_ItemDataBound(object sender, ListViewItemEventArgs e)
 if (e.Item.ItemType == ListViewItemType.DataItem)
  using (ListViewDataItem item = (ListViewDataItem)e.Item)
   // cast the ListViewDataItem to a Benefit
   Benefit benefit = (Benefit)item.DataItem;
   // create the ClientIntakeBenefitDictionary dictionary for the benefit and add it to the BenefitAtIntake control
   ClientIntakeBenefitDictionary dictionary = new ClientIntakeBenefitDictionary(benefit, new Guid(this.ContactId));

   // Create the IntakeBenefit

Displaying Role-Specific Markup With the LoginView Control



I want to know how can I display role-specific markup using loginview?

I have these three roles, Admin, Editor, Moderator

Each and every user will belog to only one of the following role groups

1. Admin, Editor,  Moderator (Some user/s will have all these three roles)

2. Admin, Editor   (Some user/s will have all these two roles)

3. Admin, Moderator (Some user/s will have all these two roles)

4. Editor, Moderator (Some user/s will have all these two roles)

5. Admin (Some user/s will have all only this role)

6. Editor (Some user/s will have all only this role)

7. Moderator (Some user/s will have all only this role)

Now I want to display some links that will be specific for each role group to which one or more users will belong. So the links I want to display for these role groups are following

1. Admin, Editor,  Moderator    => Only Links of all the pages of Admin, Editor and Moderator

2. Admin, Editor                       => Only Links of all the pages of Admin and Editor

3. Admin, Moderator                => Only Links of all the pages of Admin and Mode

Help with LoginView control


Now that some of the Security matrix has been approved and site is somewhat more functional. We are going back thru adding the loginview to the pages that need it so we can control who can adn cant see the pages and data.


Can anyone offer some assistance or links to good tutorials?

 To keep it simple, here is what i have setup.. Because if this setup, i cant access my controls and the page wont display either template. Now even though the aspx code below is a very stripped down version of what i have, the code behind has references to controls that dont show in my example, but they are there in my actual page. I Just removed alot of information to make the post more clear.


    <asp:LoginView ID="LoginView1" runat="server">
            <asp:RoleGroup Roles="Admin">
                You are an Admin!
            <asp:RoleGroup Roles="User">
                You are a user!
        <asp:GridView ID="GridView1" runa

Finding control from master page inside tabcontainer in content page


I have a codebehind.vb for a master page from which I'm trying to find a hiddenfield in the content page. I was finding it like this without a hitch...

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("hfSearch"), HiddenField)

Then I decided to add an Ajax TabContainer to the content page. Now I'm having a hard time finding the hiddenfield. I've tried these variations, but still not working.

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Can someone please help me with the syntax?

Thank you.


finding control id and setting properties in other pages


hi can anybody help me how to code,

im using a webusercontrol (hide.ascx) it has 2 buttons btn_hide,btn_expand

and in my other forms of all like(products.aspx)customers.aspx,orders.aspx

im using a panel conrol(pnl_products) where in im placing all the input controls.

i want to find the panel control in hide.ascx page and to set that

panel.visble=true/false property in this page.

so that expand and collapse the panel in each page.

Login Control , LoginView, Page Redirection


Hi and thanx for giving your time.

I have Default.aspx page with Login control.


protected void Login2_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
            //verify that the username/password is valid
            if (Membership.ValidateUser(Login2.UserName, Login2.Password))

                if (Roles.IsUserInRole(Login2.UserName, "Administrator"))

Removed text boxes from within loginview control and now nothing is returned via ValidateUser.


I removed two textboxes (textbox_LoginName and textbox_Password) and a button (button_Login) from a LoginView control by cutting and pasting. I placed them within a panel. In the code behind for the login file I removed the FindResource method that I had to use while the controls were buried within the LoginView control. This allowed my to simply use the Text properties of the textboxes as the parameters for the ValidateUser method.

The ValidateUser method was working prior to making the changes. Now, however, when called if the user is a legitimate username and password it returns no user at all - just empty strings/nulls. If the login credentials are incorrect it behaves as normal.

Here is my code:

 protected void button_Login_Click(object sender, EventArgs e)
        // Validate user against the Membership framework user store.
        if (Membership.ValidateUser(textbox_LoginName.Text, textbox_Password.Text))
            string myUser = User.Identity.Name;

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

In-Depth look at the GridView Control

In the last article we looked at few of the new controls available in Asp.net 2.0. We also talked about Grid View Control which has replaced the Asp.net 1.1 DataGrid control for good. In this article we will examine more features of the Grid View control. In this article we will see some of the common operations that can be performed using the GridView control. Apart from these operations there are many more functions that can be performed on the control and which we will see in the later articles

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.
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