Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Finish Button in CreateUserWizard doesn't validate

by the3factory 5/6/2008 8:23:00 AM
Question:

Dear All,

I am trying to add users to my website by creating a web page in which I am using Membership. I could have added the controls manually and added user by calling CreateUser() method but I decided to use CreateUserWizard Instead. I have customised the SQLMembershipProvider by adding my own setting in web.config file and using my own database.I created the in built schema in my database using aspnet_regsql.exe.

I customised the CreateUserWizard to collect additional info. The Wizard has a standard UI of its own.Now I have put the UI for the additional info after standard UI, although I could have put it before.

The additional fields that I have put are 1) DisplayName 2) Phone Number and 3 more. Now I am validating Display Name with 2 validators - a) Required Field Validator and 2) Custom Validator. But I need to do a database lookup for DisplayName to check up that a name does not EXISTs or not. I have got stuck with this one.

I have tried all kinds of things but nothing works. I have done the following:

 

1)  First I put the code within the event handler that inserts the data into the database as given below:

protected void RegisterUser_ActiveStepChanged(object sender, EventArgs e)

{

if (RegisterUser.ActiveStep.Title == "Complete")

{

WizardStep UserSettings = RegisterUser.FindControl("UserSettings") as WizardStep;

//Programmatically refrence the Textbox controls

TextBox DispName = UserSettings.FindControl("txt_dispname") as TextBox;

TextBox PhoneNo = UserSettings.FindControl("txt_phoneno") as TextBox;

TextBox Hometown = UserSettings.FindControl("txt_hometown") as TextBox;

TextBox Homepage = UserSettings.FindControl("txt_homepage") as TextBox;

TextBox Signature = UserSettings.FindControl("txt_signature") as TextBox;

string present = Convert.ToString(DateTime.Now);

MembershipUser newuser = Membership.GetUser(RegisterUser.UserName);

Guid newuserId = (Guid)newuser.ProviderUserKey;

//string newuser = Convert.ToString(newuserId);

//ViewState["UserId"] = newuserId;

ViewState["Dispname"] = DispName.Text.ToString().Trim();

ViewState["PhoneNo"] = PhoneNo.Text.ToString().Trim();

ViewState["Hometown"] = Hometown.Text.ToString().Trim();

ViewState["Homepage"] = Homepage.Text.ToString().Trim();

ViewState["signature"] = Signature.Text.ToString().Trim();

ViewState["IP"] = Request.UserHostAddress;

ViewState["IP1"] = Request.UserHostAddress;

ViewState["countryfromip"] = country(Convert.ToString(ViewState["IP1"]));

// Insert a record into UserProfiles

 

DBAccess db = new DBAccess();

if (db.checkDisplayname(Convert.ToString(ViewState["Dispname"])) == 1)

CustomValidator1.Text = "Pls choose a different Display Name";

else

{

//db.InsertintoUserProfiles(newuserId, Convert.ToString(ViewState["Dispname"]), Convert.ToInt32(ViewState["PhoneNo"]), "", present, "", Convert.ToString(ViewState["Hometown"]), Convert.ToString(ViewState["Homepage"]), Convert.ToString(ViewState["signature"]));

db.UpdateUserProfiles(newuserId, Convert.ToString(ViewState["Dispname"]), Convert.ToInt64(ViewState["PhoneNo"]), Convert.ToString(ViewState["IP"]), present, Convert.ToString(ViewState["countryfromip"]), Convert.ToString(ViewState["Hometown"]), Convert.ToString(ViewState["Homepage"]), Convert.ToString(ViewState["signature"]));

}

}

}

 

2) After the above didn't work I tried to do it using javascript and custom Validator. This works partially in the sense that it does the validation but the wizard does not complete. On the second page when I click on " FINISH" nothing happens i.e it gets stuck.

3) The third method I tried is using javascript but in a different way.Instead of calling it thru' Custom Validator I called it in the onBlur event of the text box for which I declared the handler in the Page_Load event.But this doesn't work too.

4) Finally I came across the FinishButtonClick event and put my code in there. But It doesn't work. In fact I came across several complaints in this forum which says that the nextButtonClick also doesn't work.

The code for the finish button is as below:

protected void RegisterUser_FinishButtonClick(object sender, EventArgs e)

{

WizardStep UserSettings = RegisterUser.FindControl("UserSettings") as WizardStep;

TextBox DispName = UserSettings.FindControl("txt_dispname") as TextBox;

DBAccess dba = new DBAccess();

string trimmeddispname = DispName.Text.ToString().Trim();

if (dba.checkDisplayname(trimmeddispname) == 1)

{

Label2.Text =
"Pls enter a different Display Name";

//e.Cancel = true;

}

else

Label2.Text = "";

 

}

Microsoft has made the architecture so complicated that many of the things have become a  pain on the neck.

I hope you all can find out a way out of this.

Thanks for your kind help.

 

 

 


Answer1:

Hi

Base on my understanding, you want to pass all the necessary details in each step and create user at the last finish step.

Well, you can store fields in session variables between steps using a Wizard control. then call the Membership.createuser() method at the last step as said by Joël Hébert ,  For more information, please view this thread

http://forums.asp.net/t/1141099.aspx

 


Answer2:

Hi,


My problem is not how to get the values of the controls i.e textboxes that I
add. I am able to get the values in both cases ie. when I add the Custom UI before or after the Standard UI.

My problem is that I am having a field called Display Name.I have put 2 validators to validate its input.But I also need to do a
database lookup to ensure that someone does not use an Existing display name. This is not working.
I have tried to do it in several ways which I had mentioned in my first post. I also tried to do using a third validator(custom) but doesn't work.

I want to know how to make it work.What is the best method? Database access is working fine but somehow things are
getting stuck somewhere in this case.

Thanks.


Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0