trouble setting a property on a custom web control

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 2.0

I have created a custom web control, here is it's header:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="EditUserBox.ascx.cs" Inherits="Controls_EditUserBox" %>

In another custom web user control, I use this web control:
<%@ Register Src="~/Controls/EditUserBox.ascx" TagName="Eub" TagPrefix="mb"
%>
<mb:Eub ID="Eub1" runat="server" />
(the <mb:Eub ID="Eub1" runat="server" /> is placed inside a
CreateUserWizard)

EditUserBox has a custom property:
private bool _display = true;
public bool Display
{
get { return _display; }
set { _display = value; }
}

Here is the PROBLEM:
this.Eub1.Display = false;
gives me this error:
- 'Controls_CreateUserBox' does not contain a definition for 'Eub1'

any suggestions why this don't work?
 
I have never really used the CreateUserWizard, but I have used templated
controls (You did put the Eub control inside one of the templates, didn't
you?). Try using the FindControl method of the template from the
CreateUserWizard that you put your Eub control in (and obviously do a type
conversion so that you can access it's Display property). If this is unclear
or if you need more help, try sending a little more code so we can see
exactly what you did. Good Luck!
 
thanks for posting in my thread.

I've just tried using the FindControl, but it didn't work :(
I tried FindControl 3 different ways, and all give NULL:
public partial class Controls_CreateUserBox : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Controls_EditUserBox custom =
(Controls_EditUserBox)this.FindControl("Eub1");
Controls_EditUserBox custom1 =
(Controls_EditUserBox)CreateUserWizardStep1.FindControl("Eub1");
Controls_EditUserBox custom2 =
(Controls_EditUserBox)cuwNewUser.FindControl("Eub1");
}
}

Here is the code of CreateUserWizard:
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"
Title="Initial step">
<ContentTemplate>

<div style="margin-left:auto; margin-right:auto; width:400px;
border:solid 2px black; background-color:#eeddcc; position:relative;">
<div class="sectiontitle" style="text-align:center;">Opprett ny bruker</div>
<asp:Table ID="tblEditUser" runat="server" Width="100%" BorderWidth="1"
BorderColor="Black">
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right"
Width="120">Brukernavn:</asp:TableCell>
<asp:TableCell Width="240" ><asp:TextBox ID="UserName"
runat="server" Width="100%"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:RequiredFieldValidator ID="valRequireUserName"
runat="server"
ErrorMessage="Username is required"
ControlToValidate="UserName"
SetFocusOnError="false" Display="Dynamic"
ValidationGroup="cuwNewUser">*
</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Passord:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="Password" TextMode="Password"
runat="server" Width="100%"></asp:TextBox></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Bekreft
Passord:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="ConfirmPassword"
TextMode="Password" runat="server"
Width="100%"></asp:TextBox></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">E-post:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="Email" runat="server"
Width="100%"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Spørsmål:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="Question" runat="server"
Width="100%"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Svar:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="Answer" runat="server"
Width="100%"></asp:TextBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
<mb:Eub ID="Eub1" runat="server" />
<asp:ValidationSummary ID="ValidationSummary1"
ValidationGroup="cuwNewUser"
ShowSummary="false"
ShowMessageBox="false"
runat="server" />
</div>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"
Title="Completed">
<ContentTemplate>
<div class="sectiontitle">Success</div>
A confirmation email is being sent to you.<br />
This email contain a link you need to click on to
activate your profile <br />
To continue click <asp:HyperLink ID="hlRedirect"
runat="server" NavigateUrl="~/Admin/ManageUsers.aspx">here</asp:HyperLink>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>

******************************************************
Here is some code from the custom web control which is used the above code:
public partial class Controls_EditUserBox : System.Web.UI.UserControl
{
private bool _display = true;
public bool Display
{
get { return _display; }
set { _display = value; }
}

********************************************************
Here is the first tag in the control that uses the custom control:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CreateUserBox.ascx.cs" Inherits="Controls_CreateUserBox" %>
<%@ Register Src="~/Controls/EditUserBox.ascx" TagName="Eub" TagPrefix="mb"
%>

************************************************
This webcontrol I have trouble accessing is placed on another custom web
control.

The purpose of the display property is that the web control contains a row I
sometimes want to hide.

any suggestions?
 
Sorry, I left one part out in my response. Use the FindControl method of the
ContentTemplate.Controls property of the CreateUserWizardStep. It's been a
little while since I've done what you're doing, but I know it involves the
ContentTemplate or ContentTemplateContainer (I think ContentTemplate) and
Controls properties, so fool around with those, and I think you'll be able
to get there. Good Luck!
 
Back
Top