how to access from code-behind a label into CreateUserWizard control?

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hi,

i have some problem to access from code-behind a label nested into a
CreateWizard control. I use a html-table for align purpose only.
I try to change the text property of the label with ID="UserNameLabel".

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep runat="server">
<ContentTemplate>
<table border="0">
<tr><td>Make a new account</td></tr>
<tr><td><asp:Label ID="UserNameLabel"
runat="server">Username:</asp:Label></td>
<td><asp:TextBox ID="UserName"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired"
runat="server">*</asp:RequiredFieldValidator>
</td></tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>


My attempt:
----------
Dim lb As New Label
lb = CreateUserWizard1.WizardSteps.Item(4)


(I also tried with Item(0) till 6).

Thanks for help
Ben
 
You might try something like this...

Dim mpUserNameLabel As Label

mpUserNameLabel = CType(usrWelcome.FindControl("UserName"), Label)

If Not mpUserNameLabel Is Nothing Then
mpUserNameLabel.Text = CType(Session("UserName"), String)
End If

usrWelcome is a User Control that I put together that has labels in it.

.... John
 
Hi John,

it doesn't work.

I tried this:

lb = CType(CreateUserWizard1.FindControl("UserNameLabel"), Label)
lb.Text = "ok"

but i get an error: "Object reference not set to an instance of an object"


.....
 
And you're sure that the IDof your Wizard Control is 'CreateUserWizard1' and
the ID or your label is 'UserNameLabel'?
 
Hi David, thanks for replying.

To be sure, i send you the beginning code as i tested it:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="findcontrolnested.aspx.vb"
Inherits="login" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server"><br />
<asp:ValidationSummary ID="val" runat="Server" />

<table style="width:690px;">
<tr>
<td valign="top">
<fieldset style="height: 300px; width: 320px;">
<legend></legend>
<asp:Login ID="Login1" runat="server" UserNameLabelText="username:"
LoginButtonText="Log in" PasswordLabelText="Paswoord:"
PasswordRequiredErrorMessage="Password required." >
</asp:Login>
</fieldset>
</td>
<td valign="top">
<fieldset style="height: 300px; width: 320px;">
<legend></legend>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" >
<WizardSteps>
<asp:CreateUserWizardStep ID="cuws1" runat="server">
<ContentTemplate>
<table border="0">
<tr>
<td align="center" colspan="2">
Make a new account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel"
runat="server" AssociatedControlID="UserName">username:</asp:Label></td>
<td>
<asp:TextBox ID="UserName" runat="server"
MaxLength="20"></asp:TextBox>
<asp:RequiredFieldValidator
ID="UserNameRequired" runat="server" ControlToValidate="UserName"
Font-Size="Smaller"
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
...........
</asp:Content>
 
Back
Top