G
Guest
In the below example could someone please assist in why the findcontrol
method is returning null. Is there are easy way to determine where in the
page heirarchy a control exists - I currently use the debugger and after I am
done drilling down 10 levels deep I still can't easily tell where the control
lives...
====CODE BEHIND====
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace playground
{
public class tabs : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblFolders;
private void Page_Load(object sender, System.EventArgs e)
{
// build html on fly
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<5;i++)
{
string id = "v2" + i.ToString().Trim();
sb.Append("<td name=\"" + id + "\" id=\"" + id + "\" bgcolor=\"#00e0\"
width=\"10\" runat=\"server\"><a href=\"tabs.aspx?folder=" + id +
"\">Folder</a></td>");
sb.Append("<td width=\"1\"></td>");
}
lblFolders.Text=sb.ToString();
if(Request.Params["folder"] != null)
{
highLightTab(Request.Params["folder"].ToString().Trim());
}
}
private void highLightTab(string controlID)
{
if (controlID != null)
{
// this does not find the control
HtmlTableCell td = (HtmlTableCell)Page.FindControl(controlID);
try
{
td.BgColor="yellow";
}
catch
{
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
====HTML .ASPX====
<%@ Page language="c#" Codebehind="tabs.aspx.cs" AutoEventWireup="false"
Inherits="playground.tabs" %>
<HTML>
<HEAD>
<title>tabs</title>
</HEAD>
<body>
<form id="tabs" method="post" runat="server">
<table border="1">
<tr>
<asp:Label ID="lblFolders" Runat="server"></asp:Label>
</tr>
</table>
</form>
</body>
</HTML>
method is returning null. Is there are easy way to determine where in the
page heirarchy a control exists - I currently use the debugger and after I am
done drilling down 10 levels deep I still can't easily tell where the control
lives...
====CODE BEHIND====
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace playground
{
public class tabs : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblFolders;
private void Page_Load(object sender, System.EventArgs e)
{
// build html on fly
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<5;i++)
{
string id = "v2" + i.ToString().Trim();
sb.Append("<td name=\"" + id + "\" id=\"" + id + "\" bgcolor=\"#00e0\"
width=\"10\" runat=\"server\"><a href=\"tabs.aspx?folder=" + id +
"\">Folder</a></td>");
sb.Append("<td width=\"1\"></td>");
}
lblFolders.Text=sb.ToString();
if(Request.Params["folder"] != null)
{
highLightTab(Request.Params["folder"].ToString().Trim());
}
}
private void highLightTab(string controlID)
{
if (controlID != null)
{
// this does not find the control
HtmlTableCell td = (HtmlTableCell)Page.FindControl(controlID);
try
{
td.BgColor="yellow";
}
catch
{
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
====HTML .ASPX====
<%@ Page language="c#" Codebehind="tabs.aspx.cs" AutoEventWireup="false"
Inherits="playground.tabs" %>
<HTML>
<HEAD>
<title>tabs</title>
</HEAD>
<body>
<form id="tabs" method="post" runat="server">
<table border="1">
<tr>
<asp:Label ID="lblFolders" Runat="server"></asp:Label>
</tr>
</table>
</form>
</body>
</HTML>