Category Archives: CreateUserWizard

CreateUserWizard

[RESOLVED]Access control in createuserwizard from jquery findcontrol method

Hi

I have a createuserwizard and I just want to get access to a textbox using the findcontrol jquery method  but for some reason it is not working. I get the error

‘System.Web.UI.ITemplate’ does not contain a definition for ‘FindControl’ and no extension method ‘FindControl’
accepting a first argument of type ‘System.Web.UI.ITemplate’ could be found (are you missing a using directive or an assembly reference?)

var UserNameTextbox = ‘<%= ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplate.FindControl("UserName")).ClientID %>’;

Any help would be really appreciated as to why this is happening.

Regards,

   Seamus

Are you trying to get this in JQuery ?

Try giving a ID to Element "CreateUserWizard" and then  $(‘thatID’).find(‘input[type=text][id*='tatboxID])[0].id …. can u pls give a try to find like this

 

Hi,

The answer is the following. For some reason.

var userNameTextbox = ‘<%= CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName").ClientID %>’;

ok… so there was no need of this cast ..(TextBox)….

thanks for that tip.

[RESOLVED]Display text on label when a 6 character text is entered in a textbox

I want to display a text (Example: Welcome) in a <asp:Label> when user enters a minimum of 6 characters in  a <asp:Textbox>. I want do this from client side using Java Script or anythign else.

I want to clear the text from Label if the text from Textbox is cleared and display Welcome message only if the Textbox has more than 6 characters.

Can someone please send me the code???

thank you very much in advance.

This is my Default.aspx page:

<script type="text/javascript">
    function DisplayTextOnLabel()

       {
            I NEED THE CODE AND LOGIC HERE
       }
</script>

<asp:TextBox ID="EnterName" runat="server"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server" Text=""></asp:Label>

Hi,
try this code:

<script type="text/javascript">
    function DisplayTextOnLabel(me)
   {
        if(me.value.length>5)
        {
            document.getElementById("<% DisplayWelcomeMessageLabel.ClientID %>").innerHTML=me.value;
        }
   }
</script>

<asp:TextBox ID="EnterName" runat="server" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server" Text=""></asp:Label>

//Ignore any warnings shown by VisualStudio regarding onkeyup.

Hello,

In jQuery

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
</script>

<script type="text/javascript">
    function DisplayTextOnLabel(t)
    {
        if(t.value.length>5)
        {
            $("#<%=DisplayWelcomeMessageLabel.ClientID%>").html(t.value);
        }
    }
</script>

<asp:TextBox ID="EnterName" runat="server" onkeyup="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server" Text=""></asp:Label>

Hi Raju,

I tried your code but it is generation an error messge as below:

@__w.Write("").innerHTML = me.value;rn }rn }rn</script>rnrnrn");

can you please check this for me??

are we missing any case sensitive info here???

thansk

Hi Ruchita,

I have your code but generating following error:

Error 24 The name ‘DisplayWelcomeMessageLabel’ does not exist in the current context

can you please check this??

athelli_reddy

Error 24 The name ‘DisplayWelcomeMessageLabel’ does not exist in the current context

can you please check this??

Hi,

Indeed I checked it before I posted it. It works fine in my end. Can I see what you’ve tried?

Hi Ruchita,

here is the code I have tried:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
</script>

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
        if (t.value.length > 5) {
            $("#<%=DisplayWelcomeMessageLabel.ClientID%>").html(t.value);
        }
    }
</script>

<asp:TextBox ID="UserName" runat="server" class="TextBoxStyle" Height="20" Width="225" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server"></asp:Label>

athelli_reddy

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
</script>

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
        if (t.value.length > 5) {
            $("#<%=DisplayWelcomeMessageLabel.ClientID%>").html(t.value);
        }
    }
</script>

<asp:TextBox ID="UserName" runat="server" class="TextBoxStyle" Height="20" Width="225" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server"></asp:Label>

Yeah it’s same as I told. It should work. I wonder why it’s not working for you. Are you sure is this is the whole code in your end? If you need, I can provide you the whole code I’ve tried.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="WebApplication1.Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
</script>

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
        if (t.value.length > 5) {
            $("#<%=DisplayWelcomeMessageLabel.ClientID%>").html(t.value);
        }
    }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="EnterName" runat="server" onkeyup="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server" Text=""></asp:Label>
    </form>
</body>
</html>

Hi Ruchira,

Sorry I shoud have told you earlier. My textbox and label are in <asp:CreateUserWizard>

does this matter???

athelli_reddy

Hi Ruchira,

Sorry I shoud have told you earlier. My textbox and label are in <asp:CreateUserWizard>

does this matter???

HERE IS THE FULL CODE

<asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server" />

    <asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser">
        <LayoutTemplate>
            <asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
            <asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
        </LayoutTemplate>
        <WizardSteps>
            <asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
                <ContentTemplate>
                    <h2>
                        Create a New Account
                    </h2>
                    <p>
                        Passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length.
                    </p>
                    <span class="failureNotification">
                        <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
                    </span>
                    <asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"

                         ValidationGroup="RegisterUserValidationGroup"/>
                    <div class="NewRegistrationTableStyleclass">
                        <%–<fieldset class="register">–%>
                            <legend>Account Information</legend>
                            <p>
                                <asp:TextBox ID="UserName" runat="server" class="TextBoxStyle" Height="20" Width="225" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
                                <asp:Label ID="DisplayWelcomeMessageLabel" runat="server"></asp:Label>

</ContentTemplate>
                <CustomNavigationTemplate>
                </CustomNavigationTemplate>
            </asp:CreateUserWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>

And where are the javascript coding part? Can you please provide the full markup so I can test it locally here?

Hi Ruchira,

Java script is also in the same page:

here is my full coee

Register.aspx page

<%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Register.aspx.cs" Inherits="Account_Register" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="mainContent">
<div id="content">
<br />

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8">
</script>

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
        if (t.value.length > 5) {
            $("#<%=DisplayWelcomeMessageLabel.ClientID%>").html(t.value);
        }
    }
</script>

<asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server" />

    <asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser">
        <LayoutTemplate>
            <asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
            <asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
        </LayoutTemplate>
        <WizardSteps>
            <asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
                <ContentTemplate>
                    <h2>
                        Create a New Account
                    </h2>
                    <p>
                        Passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length.
                    </p>
                    <span class="failureNotification">
                        <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
                    </span>
                    <asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"

                         ValidationGroup="RegisterUserValidationGroup"/>
                    <div class="NewRegistrationTableStyleclass">
                        <%–<fieldset class="register">–%>
                            <legend>Account Information</legend>
                            <p>
                                <asp:TextBox ID="UserName" runat="server" class="TextBoxStyle" Height="20" Width="225" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
                                <asp:Label ID="DisplayWelcomeMessageLabel" runat="server"></asp:Label>

</ContentTemplate>
                <CustomNavigationTemplate>
                </CustomNavigationTemplate>
            </asp:CreateUserWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>

</div>
</asp:Content>

Hi Ruchira, I also have:

<asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtenderForUserName" runat="server" TargetControlID="UserName" WatermarkText=" User Name" WatermarkCssClass="TextboxWaterMarkClass" >
                                </asp:TextBoxWatermarkExtender>
                                <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"

                                     CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."

                                     ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>

for the Textbox

Hi Ruchira,

I have tested your code in a test file  and it is working.

It is NOT workig if the controls are in <asp:CreateUserWizard>

I need to find a way to fix that..

do you know how to fix it??

Pheew! Sorted it out finally. Since your textbox is inside the createuserwizard, you cannot directly reference it by id. You have to use the FindControl method. Please see my modified function below.

function DisplayTextOnLabel(t) {
    if (t.value.length > 5) {
       $("#<%=((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html(t.value);
    }
}

Now it will work :)

Try this

<script type="text/javascript">
    function DisplayTextOnLabel(me)
   {
       var textbx = document.getElementById("<% EnterName.ClientID %>");
        if(textbx.value.lenght>5)
        {
            document.getElementById("<% DisplayWelcomeMessageLabel.ClientID %>").innerHTML=textbx;
        }
   }
</script>

<asp:TextBox ID="EnterName" runat="server" onkeydown="DisplayTextOnLabel(this);"></asp:TextBox>
<asp:Label ID="DisplayWelcomeMessageLabel" runat="server" Text=""></asp:Label>

Hi Ruchira,

thanks for looking into this but I am still getting an error message as below:

"Unable to cast object of type ‘System.Web.UI.WebControls.Label’ to type ‘System.Web.UI.WebControls.TextBox’"

can you please look into this???

Hi Ruchira,

I have fixed it with a small change as below(Textbox to Label):

$("#<%=((Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html(t.value);
thank you very much for helping here.

Ruchira,
I have another quick question?
Now, If I enter more than 6 characters in my Textbox, Label will display the message.
When I delete the text from Textbox after entering, how can I make sure even Label is also removing the text if the Textbox has less then 6 characters?

here is the code:
<script type="text/javascript">
    function DisplayTextOnLabel(t) {
    if (t.value.length > 5) {
        $("#<%=((Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html("Welcome");
    }
}
</script>


Hi Ruchira,
Can you also try to give me  a soluting for the following issue?

Current solution: When I enter more than 6 characters in Textbox, Label will display a message saying "Welcome"
After that, if the user deletes the text from Textbox or enters less than 5 characters, I do not want to show the message in Lable.
can you please tell me how can I solve this?

Here is my code

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
    if (t.value.length > 5) {
        $("#<%=((Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html("Welcome");
    }
}
</script>

Change your code as below then.

<script type="text/javascript">
    function DisplayTextOnLabel(t) {
    if (t.value.length > 5) {
        $("#<%=((Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html("Welcome");
    }
    else
    {
        $("#<%=((Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("DisplayWelcomeMessageLabel")).ClientID%>").html("");
    }
}
</script>

Hi Ruchira,

You are the GEM. You solved my prodblem man.

Thanks a ton.

[RESOLVED]Display Textbox depending upon the value slected in drop down list

I want to display a <asp:Textbox> depending upon the value slected in <asp:DropDownList> (Example: 1). I want do this from client side using Java Script or anythign else but not on postback. If i select any other value in DropDownList, do not show Textbox.

Can someone please send me the code???

thank you very much in advance.

This is my Default.aspx page:

<script type="text/javascript">
    function DisplayConditionalTextbox()

       {
            I NEED THE CODE AND LOGIC HERE
       }
</script>

<asp:DropDownList ID="NewsSourceDdl" runat="server">
                                                <asp:ListItem >1 </asp:ListItem>
                                                <asp:ListItem >2 </asp:ListItem>
                                                <asp:ListItem >3 </asp:ListItem>
                                                <asp:ListItem >4 </asp:ListItem>
</asp:DropDownList>

<asp:TextBox ID="ConditionalTextbox" runat="server"> </asp:TextBox>

Hi,

Check the below code!

<asp:DropDownList ID="NewsSourceDdl" runat="server" onchange="DisplayConditionalTextbox();" >
                                                <asp:ListItem >1 </asp:ListItem>
                                                <asp:ListItem >2 </asp:ListItem>
                                                <asp:ListItem >3 </asp:ListItem>
                                                <asp:ListItem >4 </asp:ListItem>
</asp:DropDownList>
 
<asp:TextBox ID="ConditionalTextbox" runat="server"> </asp:TextBox>


<script type="text/javascript">
    document.getElementById("<%=ConditionalTextbox.ClientID %>").style.display = "none";
    function DisplayConditionalTextbox() {
        var ddlID = document.getElementById("<%=NewsSourceDdl.ClientID %>");
        if (ddlID.options[ddlID.selectedIndex].value == 1) {
            document.getElementById("<%=ConditionalTextbox.ClientID %>").style.display = "block";
        }
    }
 

    </script>

Hope it helps u…

Thanks Reddy.

Does this code workd if the controls are in <asp:CreateUserWizard> ???

Hi,

For accessing the content in the CreateUserWizard, check the following link!

http://forums.asp.net/t/1581824.aspx/1

Hope it helps u…

 

 

Hello,

Try this then

<asp:DropDownList ID="NewsSourceDdl" runat="server" onchange="DisplayConditionalTextbox();" >
        <asp:ListItem >1 </asp:ListItem>
        <asp:ListItem >2 </asp:ListItem>
        <asp:ListItem >3 </asp:ListItem>
        <asp:ListItem >4 </asp:ListItem>
</asp:DropDownList>
 
<asp:TextBox ID="ConditionalTextbox" runat="server" style="display:none"> </asp:TextBox>

<script type="text/javascript">
    function DisplayConditionalTextbox() {
        if ($("#<%=((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("NewsSourceDdl")).ClientID%> option:selected").text() == "1") {
            $("#<%=((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("ConditionalTextbox")).ClientID%>").show();
        }
        else
           $("#<%=((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("ConditionalTextbox")).ClientID%>").hide();
    }
</script>

[RESOLVED]Unable to access my textbox control from code-behind file .

i am using visual studio pro 2012 , i started editing asp.net web template given in VS , all went fine but then i added sql data source to connect my application to sql server, in register.aspx i have some textbox controls , but when i am trying to use them
in register.aspx.cs neither the intellisense is popping up nor i can use them , do i have to tweak any configuration in given template ?? , please resolve my issue.

Do the textbox have the runat server attribute? Make sure you have that. Else, it could be missing ID attribute.

This is how a default asp.net textbox should look like:

<asp:TextBox runat="server" ID="Your_Textbox_ID" />

yes it has both of them but still unable to use .

Check the Register Directive of the aspx page. check whether the codefile name and Inherits are correct… Also chech the partial class name in the code behind..

the public partial class name is "Register : Page" & codefilename & inherits name are  CodeBehind="Register.aspx.cs" Inherits="PMS.Account.Register" %>

Hi Kranthi

The Page tag and the class declarations should be as follows:

Page:

<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true"
    CodeFile="Invoices.aspx.cs" Inherits="PMO_Invoices" %>

Code behind:

public partial class PMO_Invoices : System.Web.UI.Page
{
 //
}

and here the file name is Invoices.aspx.cs

Please check both of these in your code.

Is PMS and Account two folders inside which the Register File is present..

Try using:

Inherits="PMS_Account_Register"

Also correct  the partial class in the same way..

The best Idea would be to create a new file with codebehind by the same name and copy the content of register page and its codebehind.. That will solve your problem.

what is invoices ??

PMS is the solution name & account is folder name where register.aspx.cs is present.

Don’t get confused with the names kranthi, those are just names which i’m using in my project.

in your case it should be

<%@ Page Title="" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true"
    CodeFile="Register.aspx.cs" Inherits="PMS.Account.Register" %>
public partial class Register : System.Web.UI.Page
{
 //
}

and change the file names as Register.aspx , Register.aspx.cs

yes i named everything as you said naresh , but still the same issue .

Can you paste the starting lines of page and code behind files here. so that we can check.

Did you put your TextBox under form ?

Are you using AjaxToolkit?

here is my entire solution naresh , please download it  & see in VS 2012 .

https://app.box.com/s/o3ut7t4w02qklj9atljk 

Hi Kranthi

After checking your solution, i came to knw that you’re working with CreateUserWizard control.

You can access the Textbox inside the CreateUserStep as Follows:

TextBox userName = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");

If you want to customize the default behavior/look of this wizard, you can follow the below reference.

http://msdn.microsoft.com/en-us/library/ms178342.ASPX

Let us know if you still have any issues.

can i safely wipeoff create user wizard completely from my page so that i can use my custom behaviours for my custom controls ??