Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - trouble setting a property on a custom web control

 
Thread Tools Search this Thread
Old 10-10-2008, 02:07 PM   #1
Default trouble setting a property on a custom web control


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
  Reply With Quote
Old 10-10-2008, 04:18 PM   #2
Nathan Sokalski
 
Posts: n/a
Default Re: trouble setting a property on a custom web control
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
  Reply With Quote
Old 10-10-2008, 05:05 PM   #3
Jeff
 
Posts: n/a
Default Re: trouble setting a property on a custom web control
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
  Reply With Quote
Old 10-10-2008, 05:37 PM   #4
Nathan Sokalski
 
Posts: n/a
Default Re: trouble setting a property on a custom web control
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
  Reply With Quote
Old 10-10-2008, 06:37 PM   #5
Jeff
 
Posts: n/a
Default thanks
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46