 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

May 5th, 2013, 05:21 AM
|
|
Registered User
|
|
Join Date: May 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
P. 596 Note question
Hello,
I have followed the NOTE on p. 596 of Chapter 16 which was proposing a way to check if a given user name already exists.
The user registration feature works, an email is sent.
The user name exists check is executed correctly when the user name text box looses focus and displays the error message if necessary (tested in IE and FF).
But, when a new user registers, they are sent back to the SignUp page and IE displays a popup Webpage Error of:
Do you want to debug this webpage?
This webpage contains errors that might prevent it from displaying or working correctly. If you are not testing this webpage, click No
Line: 232
Error: Unable to get property 'parentNode' of the undefined or null reference
When I click on "Yes" line 232 is marked in yellow:
userNameRequiredMessage.parentNode.appendChild(err orMessage);
and the Console says:
SCRIPT5007: Unable to get property 'parentNode' of undefined or null reference
SignUp.aspx, line 232 character 5
I guess the control is no longer available to the page after successful registration; the message of "Complete
Your account has been successfully created. " is displayed when the error happens.
I am not sure how to fix this issue and I was wondering if somebody could help me please.
-------------
My SignUp.aspx has the following:
<%@ Page Title="Sign Up for a New User Account at Planet Wrox" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="SignUp.aspx.cs" Inherits="_SignUp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" MailDefinition-BodyFileName="~/App_Data/SignUpConfirmation.txt" MailDefinition-Subject="Your New Account at Planet.Wrox.com" ClientIDMode="Static">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
<script type="text/javascript">
var userNameTextBox = $get('UserName');
var userNameRequiredMessage = $get('UserNameRequired');
var errorMessage = document.createElement('span');
errorMessage.style.visibility = 'hidden';
errorMessage.style.color = 'red';
errorMessage.innerHTML = 'User name already taken';
userNameRequiredMessage.parentNode.appendChild(err orMessage);
// add a handler to call the UserNameExists function when the userNameTextBox looses focus:
$addHandler(userNameTextBox, 'blur', UserNameExists);
function UserNameExists() {
var userName = userNameTextBox.value;
// call the page method in the code behind file on the server to check if the user already exists in the DB
PageMethods.UserNameExists(userName, UserNameExistsCallback);
}
function UserNameExistsCallback(result) {
errorMessage.style.visibility = result ? 'visible' : 'hidden';
}
</script>
</asp:Content>
----------------
My SignUp.aspx.cs has the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Services;
public partial class _SignUp : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static bool UserNameExists(string yourName)
{
return Membership.GetUser(yourName) != null;
}
}
|
|

May 5th, 2013, 06:20 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Either redirect to another page or add a check for null in the code that gets a reference to the fields:
Code:
var userNameTextBox = $get('UserName');
var userNameRequiredMessage = $get('UserNameRequired');
if (userNameRequiredMessage != null)
{
// rest of your code here
}
Cheers,
Imar
|
|

May 5th, 2013, 07:21 AM
|
|
Registered User
|
|
Join Date: May 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar, it worked 
|
|

June 24th, 2013, 01:06 PM
|
|
Registered User
|
|
Join Date: Oct 2011
Posts: 5
Thanks: 3
Thanked 1 Time in 1 Post
|
|
'UserNameRequired' property
Hi Imar,
In your code below on NOTE of p596
var userNameTextBox = $get('UserName');
var userNameRequiredMessage = $get('UserNameRequired');
if (userNameRequiredMessage != null)
{
// rest of your code here
}
......
I can see the 'UserName' in CreateUserWizard1 properties, but I can not see 'UserNameRequired' anywhere in the properties. I see the property of 'UserNameRequirederrorMessage' there. They are not the same....
Can you tell me how I can see this 'UserNameRequired' property?
Thanks.
Han
|
|

June 24th, 2013, 02:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
UserNameRequired is the control created by ASP.NET to display the error message held by UserNameRequirederrorMessage. You typically don't need to access this control directly from an ASPX page.
If you do have the need, open the wizard's Smart Task Panel and click Customize Create User Step.
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|
 |
|