![]() |
|
|
|||||||
![]() |
ASP Net - trouble setting a property on a custom web control |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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? Jeff |
|
|
|
|
#2 |
|
Posts: n/a
|
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! -- Nathan Sokalski http://www.nathansokalski.com/ "Jeff" <> wrote in message news:... > 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? > Nathan Sokalski |
|
|
|
#3 |
|
Posts: n/a
|
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.FindCo ntrol("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? Jeff |
|
|
|
#4 |
|
Posts: n/a
|
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! -- Nathan Sokalski http://www.nathansokalski.com/ "Jeff" <> wrote in message news:... > 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.FindCo ntrol("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? > Nathan Sokalski |
|
|
|
#5 |
|
Posts: n/a
|
it was the ContentTemplateContainer, problem is solved
"Nathan Sokalski" <> wrote in message news:... > 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! > -- > Nathan Sokalski > > http://www.nathansokalski.com/ > > "Jeff" <> wrote in message > news:... >> 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.FindCo ntrol("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? >> > > Jeff |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamically added TreeNode Control not render my custom attribute | venkyzealous | Software | 0 | 05-10-2008 03:46 PM |
| Custom control dropdownlist - need advice | tcstom | Software | 0 | 04-18-2008 11:28 AM |
| Mind Control and CIA'S BOURNE IDENTITY PLOT | soleilmavis@gmail.com | DVD Video | 2 | 08-03-2007 09:54 PM |
| Getting error in Custom control | ShakilaRahmanLaboni | Software | 2 | 08-01-2007 02:38 PM |
| ASP.NET: User Control Events is Not Displaying in a Property Window | BabuA | Software | 0 | 09-14-2006 05:44 PM |