Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 2nd, 2013, 02:29 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default ch 16 - p.596 - Checking the Existence of an ASP.NET Membership Username with ASP.NET

Imar,

Thank you so much for this article! I was able to successfully add this feature to the sign up page. Very excited to get this working! It helped me get a better understanding of how page methods work and when to use them.

I had a question related to the view source. When I try to view the source after successfully getting the "User name already taken" message to the right of the user name text box, I noticed that "User name already taken" span element is not visible in the source (under the Sign Up for Your New Account section). Is this the expected behavior?

Thanks so much.
Tulsi
Reply With Quote
  #2 (permalink)  
Old December 2nd, 2013, 03:21 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Does your page contain an UpdatePanel? That would add the code dynamically so it doesn't show up when you view the source directly. You can use the IE Developer tools or Firebug to diagnose the run-time HTML.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old December 3rd, 2013, 01:53 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Thank you for suggesting the IE Developer tools! I was not aware that there was such a useful tool to see exactly what data is sent to the browser. Using this tool, I am now able to see the span element for "User Name already taken".

I'm not sure as to why it doesn't show up when I view the source directly. The Signup.aspx page does not contain an UpdatePanel, but it is based off a MasterPage that has a reference to a scriptmanager Ajax control. Could this be the reason?

Thanks,
Tulsi
Reply With Quote
  #4 (permalink)  
Old December 3rd, 2013, 02:09 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Tulsi,

When are you looking at the source code? The code is only available after a postback (as far as I know) as it's a server side check so it doesn't make sense to submit it on the initial request. You can check it out by creating a new page with a plain CreateUserWizard control on it.

IMar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Tulsi (December 19th, 2013)
  #5 (permalink)  
Old December 19th, 2013, 02:25 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Imar,

Thank you...I am now able to see the "User name already taken" message perfectly. This message is generated via the Javascript on the SignUp.aspx page.

I think my confusion was due to my misunderstanding of how "View Source" works.

Here's how I understand it now....It seems that "View Source" should display the resulting HTML that is sent to the browser by the server after processing the page. It should not show any HTML that is added dynamically by Javascript in the page. In order to view and diagnose the dynamically added HTML, one needs to use IE Developer tools or Firebug.

I've been trying different things with this tool and realizing how powerful it is. I'm even able to debug the client side javascript with it...this is awesome!

Thank you so much again!

Tulsi
Reply With Quote
  #6 (permalink)  
Old December 19th, 2013, 02:47 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
Here's how I understand it now....It seems that "View Source" should display the resulting HTML that is sent to the browser by the server after processing the page. It should not show any HTML that is added dynamically by Javascript in the page. In order to view and diagnose the dynamically added HTML, one needs to use IE Developer tools or Firebug.
Yes, that's exactly how it is. Some browsers, such as FireFox, also have a "View Selection Source" menu command that shows the DOM (that includes the HTML added by JavaScript) instead of just the original source.

Quote:
I've been trying different things with this tool and realizing how powerful it is. I'm even able to debug the client side javascript with it...this is awesome!
I completely agree! ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Tulsi (January 23rd, 2014)
  #7 (permalink)  
Old February 4th, 2014, 03:33 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Hi Imar,

I'm not sure as to why the following error just surfaced now when using IE ....

If I try to type in a pre-existing username, I successfully get the "User Name already taken message" message when using IE and Google Chrome.

But I run into the following error when I try to sign up for a new account and I click "Create User" in IE (works fine in Google Chrome): "Line: 252 Error: Unable to get property 'parentNode' of undefined or null reference".

I'm re-directed to screen which says "Your account is created successfully" followed by this WebPage Error.

I'm not sure what I'm doing incorrectly.

Thanks.
Tulsi
Reply With Quote
  #8 (permalink)  
Old February 4th, 2014, 04:45 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you post the code that causes the error? Do you know where it's coming from?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old February 4th, 2014, 10:21 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Here's the signup.aspx page:

Error happens on the following line: userNameRequiredMessage.parentNode.appendChild(err orMessage);

Quote:
<%@ Page Title="Sign Up for a New Account at Planet Wrox" Language="C#" MasterPageFile="~/MasterPages/FrontEnd.master" AutoEventWireup="true" CodeFile="Copy of 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" ClientIDMode="Static">
<MailDefinition BodyFileName="~/App_Data/SignUpConfirmation.txt"
Subject="Your New Account at PlanetWrox.com">
</MailDefinition>
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>


<asp:Content ID="Content3" ContentPlaceHolderID="cpClientScript" Runat="Server">
<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);

$addHandler(userNameTextBox, 'blur', UserNameExists);

function UserNameExists() {
var userName = userNameTextBox.value;
PageMethods.UserNameExists(userName, UserNameExistsCallback);
}

function UserNameExistsCallback(result) {
errorMessage.style.visibility = result ? 'visible' : 'hidden';
}
</script>
</asp:Content>

Here's the Signup.cs file:
Quote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Security;

public partial class SignUp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

// Check existence of ASP.Net Membership UserName with ASP.NET AJAX
[WebMethod]
public static bool UserNameExists(string yourName)
{
return Membership.GetUser(yourName) != null;
}

}

Thanks,
Tulsi
Reply With Quote
  #10 (permalink)  
Old February 5th, 2014, 12:07 PM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Your custom code also fires after the postback in which case the controls like UserNameRequired are no longer present.

I see a few solutions:

1. Redirect the user to a "thank you for registering" page that doesn't have this code.
2. Wrap the code in a panel and set the Visible property to False when the user has been created so this code won't be sent to the browser.
3. Rewrite the JavaScript code so it takes the case where these controls don't exist into account.

Hope his helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Membership and ActiveDirectory Quick209 ASP.NET 2.0 Professional 0 June 13th, 2007 12:41 PM
Help with ASP.NET Membership VerbatimBOT SQL Server 2000 6 May 2nd, 2007 01:58 PM
Roles and membership asp.net 2 zeeshannasir ASP.NET 1.x and 2.0 Application Design 1 September 22nd, 2006 03:34 AM
Roles and membership asp.net 2 zeeshannasir ASP.NET 2.0 Basics 2 September 15th, 2006 07:24 AM
Checking for controls existence .NET 2.0 sarosh General .NET 0 March 1st, 2006 02:30 AM



All times are GMT -4. The time now is 05:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.