Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2012, 11:57 AM
Authorized User
 
Join Date: Feb 2007
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default FindControl from an userControl inside un Accordion in the base aspx page

Hi,
I have an aspx page (Default.aspx) with an Accordion control and a button (the page is based on a master page).
Inside one Pane of this Accordion I have an userControl, something like this:

<Content>

<ucDetails:Details ID="userControlDetails" runat="server" />

</Content>

Now I need to access of the Enabled property of the button in the aspx page inside my userControl.

Until now I've tried:

Button btnSend1 = (Button) this.NamingContainer.FindControl("btnSendRequest") ;
Button btnSend2 = (Button) Page.Parent.Parent.FindControl("btnSendRequest");
Button btnSend3 = (Button) Page.Parent.FindControl("btnSendRequest");

The first one return NULL
and the others return exception ("Object reference not set of an instance...").

Where I'm wrong?

Thanks in advance.

Luigi
 
Old February 13th, 2012, 04:02 PM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default test it step by step

Hi Luigi

Try on the page and make sure that it works, then test in next level (in the Pane of an Accordion)

WebUserControl.ascx:
====================
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Button ID="Btn1" Text="Button In Usercontrol" runat="server" onclick="Btn1_Click" />
<asp:Label ID="ResultLabel" runat="server"></asp:Label>


WebUserControl.ascx.cs:
=====================
protected void Btn1_Click(object sender, EventArgs e)
{
ResultLabel.Text = ((Button)this.NamingContainer.FindControl("btnSend Request")).Text;
}


default.aspx:
=====================
<asp:Button ID="btnSendRequest" Text="Send Request Button" runat="server" />
<uc1:WebUserControl ID="WebUserControl1" runat="server" />



it works! so you can test in other situations.



your firstname brings 'Luigi Collina' in my mind!!
__________________
happy every time, happy every where

Reza Baiat
 
Old February 14th, 2012, 04:38 AM
Authorized User
 
Join Date: Feb 2007
Posts: 39
Thanks: 2
Thanked 2 Times in 2 Posts
Default

It gives me a System.NullReferenceException :-(
Luigi

PS
Who is Luigi Collina?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested controls in UserControl return null (FindControl) Lug Velez Schmitz ASP.NET 3.5 Professionals 2 September 6th, 2010 06:56 AM
FindControl method get nothing in Gridview with Master Page Michael YoeH ASP.NET 3.5 Professionals 4 August 28th, 2009 03:42 AM
Accessing and using an ActiveX from inside a HTML page hosted inside a WebBrowser con adyrotaru C# 2005 2 June 25th, 2009 04:21 PM
error compiling link usercontrol inside sharepoint mcarola ASP.NET 2.0 Professional 0 December 4th, 2008 03:51 PM
aspx inside of css nutrino CSS Cascading Style Sheets 6 December 2nd, 2005 05:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.