Solved

need to create a two page profile web site.

Posted on 2008-11-01
21
285 Views
Last Modified: 2008-11-07
I have to build a two page registration with the asp.net built in registration.

 If you goto the site omegalove.com and click on registration then u can see that I have only one page.

How can I build the second.
I will be using the ProfileCommon pc = Profile.GetProfile(user.UserName);
               

protected void imgRegister_Click(object sender, System.EventArgs e)
        {

            char Gender = ' ';
            //Gender = rdoFemale.Checked ? 'F' : ' ';
            //Gender = (rdoMale.Checked && Gender == ' ') ? 'M' : Gender;

            string number_server_side = (string)Session[ADSSAntiBot.SESSION_CAPTCHA];
            if (number_server_side == TextBox_number.Text)
            {
                Label_valid.Visible = true;
            }
            else
            {
                Label_invalid.Visible = true;
                return;
            }

            try
            {

                MembershipUser user = Membership.CreateUser(txtUserName.Text, txtPassword.Text, txtEmail.Text);

                //ProfileCommon pc = Profile.GetProfile(user.UserName);
                //pc.Email = txtEmail.Text;
                //pc.FullName = txtFullName.Text;
                //pc.DOB = Datepicker.Selected_Date;
                //pc.Gender = Gender.ToString();

                //pc.City = ddlCity.SelectedValue;
                //pc.Region = ddlRegion.SelectedValue;
                //pc.Country = ddlCountryRegister.SelectedValue;
                //pc.Save();

                //lblMessage.Text = "User created successfully!";

                //// Generate Confirmation GUID
                //string sConfirmationGUID = System.Guid.NewGuid().ToString("N");
                //string sUserIP = Request.UserHostAddress;
                //string sSessionID = this.Session.SessionID;


                for (int i = 0; i < Session.Count; i++)
                {
                    Response.Write("<p>" + Session.Keys.ToString() + " - " + Session.ToString() + "</p>");
                }

                Response.Redirect("Registered.aspx");


            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }

 

        }

0
Comment
Question by:mathieu_cupryk
  • 11
  • 10
21 Comments
 
LVL 12

Expert Comment

by:techExtreme
ID: 22860455
Hello, can you elaborate on what you are trying to achieve?  because adding another page is just rightclicking on your project and selecting add new item -> aspx page.   I'm not sure what you want to achieve.
0
 

Author Comment

by:mathieu_cupryk
ID: 22862715
then i must create another page and how do I store the variables.
if this is the first page register_Click
{
                ProfileCommon pc = Profile.GetProfile(user.UserName);
                pc.Email = txtEmail.Text;
                pc.FullName = txtFullName.Text;
                pc.DOB = Datepicker.Selected_Date;
                pc.Gender = Gender.ToString();

                pc.City = ddlCity.SelectedValue;
                pc.Region = ddlRegion.SelectedValue;
                pc.Country = ddlCountryRegister.SelectedValue;
                pc.Save();
}

should i have a redirect or use server.transfer and for the next page
I will have to use update.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22867780
Hi,
you need not to worry about how they are stored in database,
because asp.net handles that for you.
What you only should care about is that what informatino you
want to store for each user.
For example, I want to store Name and Age of each user in
the profile table, hence I will declare two properties
in the profile tag in my web.config file like this:


    <profile >
      <properties>
        <add name="Name" allowAnonymous="true" />
        <add name="Age" allowAnonymous="true" type="System.Int16"/>
      </properties>
    </profile>

That's how you tell asp.net that you will be storing these two properties and
that asp.net must handle how it is stored in database.



To access them use code something like this:

   nameTextBox.Text = Profile.Name;
   ageTextBox.Text = Profile.Age.ToString();



And you can update the profile properties as you have already written code for it.
No need to worry about the internal structure of how they are stored in the database.
Hope it helped!
0
 

Author Comment

by:mathieu_cupryk
ID: 22869305
this I know but if it is two pages how should I do this?
if you goto omegalove.com registration page. you will see one
page. I will need to make it two.
Note I am not using <asp:CreateUserWizard runat="server" ID="CreateUserWizard1" AutoGeneratePassword="False"
      ContinueDestinationPageUrl="~/Default.aspx" FinishDestinationPageUrl="~/Default.aspx" OnFinishButtonClick="CreateUserWizard1_FinishButtonClick" OnCreatedUser="CreateUserWizard1_CreatedUser">

0
 

Author Comment

by:mathieu_cupryk
ID: 22887018
I am using the personalization profile. I have a two page registration and I am not sure how I should deal with this,

Options: Server.Transfer

                  Response.Redirect

                   Panel driven

 

Which way would u go about this?

RegisterPage1.aspx

 

protected void btnRegisterPage1_Click(object sender, EventArgs e)
        {
          MembershipUser user=  Membership.CreateUser(UserId, UserId, txtEmail.Text);
            if(user!=null)
            {
                //don't really need next line, just habit...
                FormsAuthentication.Authenticate(UserId, UserId);
                WebProfile Profile = new WebProfile();
                Profile.Initialize(UserId,true);
                Profile.FirstName = this.txtFirstName.Text;
                Profile.LastName = this.txtLastName.Text;
                Profile.Newsletter = this.chkNewsLetter.Checked;
                Profile.Email = this.txtEmail.Text;
                Profile.Save();

                GenericIdentity userIdentity = new GenericIdentity(UserId);
                GenericPrincipal userPrincipal =
                  new GenericPrincipal(userIdentity, new string[ { "User" });
                Context.User = userPrincipal;

                if (!Roles.IsUserInRole(User.Identity.Name, "User"))
                {
                    PAB.Web.Providers.SimpleSqlRoleProvider prov = new SimpleSqlRoleProvider();
                    NameValueCollection config = new NameValueCollection();
                    config["connectionStringName"] = "LiveId";
                    System.Configuration.ConnectionStringSettings ConnectionStringSettings =
                        System.Configuration.ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
                    prov.Initialize("",config);
                    prov.AddUsersToRoles(new string[ {User.Identity.Name}, new string[ {"User"});
                }
               
                Response.Redirect("Default2.aspx");
            }
            else
            {
               
            }

        }
    }

0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22888703
Hi, your problem will be solved using Cross-Page Posting.

Your Scenario/ Problem:
You are creating a multi-page (aspx pages) form that collects different information on each page.

SOLUTION:

You can configure a button on say page1.aspx to post to page2.aspx and you will be able to
access page1.aspx controls using special properties in page2 as it is, no need to use
Session variables!

DETAILS:

The Page class exposes a property named PreviousPage. If the source page and target page are in
 the same ASP.NET application, the PreviousPage property in the target page contains a reference
to the source page


To Enable Crosspage postback from page1.aspx to page2.aspx,
you introduce a button in page1.aspx which posts to page2.aspx like this

<asp:Button runat="server" ID="_button"
                PostBackUrl="~/Page2.aspx" Text=" = " />


The following code example shows how you can get the value of the TextBox1 control on the source page.

if (Page.PreviousPage != null)
{
    TextBox SourceTextBox =
        (TextBox)Page.PreviousPage.FindControl("TextBox1");
    if (SourceTextBox != null)
    {
        Label1.Text = SourceTextBox.Text; //Now this label1 is on your current page i.e. (page2.aspx)
    }
}



Hopefully you got the idea of what should be done.

Now further down, you may be thinking what if I want to access data of both page1.aspx -> page2.aspx
in page3.aspx , now there's no previouspage of previouspage or something like that but
you can do it easily.

For example If i'm collection data 'a' and 'b' in page1.aspx and 'c' and 'd' in page2.aspx now i want
a,b,c,d all of them in page 3, then on page2.aspx using previouspage I'll be storing a,b in a textbox/hidden
field and then in page3.aspx i'll get 'c', 'd' and 'a,b'  as three values from page2.aspx as part of work
i did in page2.  

So in this way I can continue propagating my values to number of pages. This is a solution where you are not
using session variables, else you can do it by session variables or less secure query strings also but

In case you are not sure about the logic yet, need something to refer to, here's a very good tutorial regarding the topic I discussed in greater depth.

http://msdn.microsoft.com/en-us/library/ms178139.aspx

Read it for a better understanding but you can very well start off with what I wrote.

I guess this will solve your problem.


0
 

Author Comment

by:mathieu_cupryk
ID: 22888756
U see I can use the userid in the second page.

However, how can I use
ProfileCommon pc = Profile.GetProfile(user.UserName); this concept
if someone leaves the page.
               
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22888794
Hello,
I guess you should avoid using 'Membership.Createuser'... till you reach your last registration page be it page2 or page 3...

Till that you should use variables/hidden fields etc.. to store values and pass on using crosspage postback or session etc.... Then on last page create the user and profile with all the information at your disposal.
 Its generally not good to create something on page1 and keep updating that stuff for rest of the registration forms , when you split the whole registration process over multiple pages.


0
 

Author Comment

by:mathieu_cupryk
ID: 22888826
is there an example of a site that does this?
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22888972
Hi,
For the code (not the one i mentioned), if you just want to update a profile from a page,
go thru this link:
http://asp.dotnetheaven.com/util/srcview.aspx?path=~/aspnet/samples/profiles/ProfileProperties.src

there under the sub btnUpdatePreferences_Click, the user is updating current user's profile


Here's link for all profile information (with SourceCode) that you'll need

http://asp.dotnetheaven.com/aspnet/doc/profile/default.aspx
It contains information regarding:

Anonymous Profiles
Anonymous Profiles
Migrating Anonymous Profiles to Authenticated Profiles
Defining Profile Properties with a Custom Base Class
Defining Profile Properties with a Custom Base Class
Deleting a Profile
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mathieu_cupryk
ID: 22889040
for the update, they are using a redirect? I don't see cross-page posting.
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22889159
I already mentioned I'm posting code for profile updating not mine, coz its not available directly (i.e updating profiles via cross page postback etc..). I suggested you a solution.
I'm not sure if there is a ready made solution available online that you can use.
0
 

Author Comment

by:mathieu_cupryk
ID: 22889192
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22889223
Yes it is a very good control, but It is against your Design Decision of having seperate registrtion forms and code.
Basically it will reside on the same page, i.e. if you place multiview control on page1.aspx,  your registration will be completed on page1.aspx itself, no second page.

Multiview can display at a time one of its views, so then you have to change your design such that you store your controls of page1 in first view, page2 in second view etc...  

Now on the next button/register button of first view, you just change multiview's active view and move to second view (on the same page tho)  

If its ok with you, ya can go ahead with it.
0
 

Author Comment

by:mathieu_cupryk
ID: 22889259
this is true! So Cross paging is used in 3.5?
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22892147
No its an old concept, u can use it in .net 2.0 framework too5
0
 

Author Comment

by:mathieu_cupryk
ID: 22892777
what is there in 3.5?
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22895197
There is nothing new in 3.5 framework that can help you with this. I wonder why you want to use 3.5! This is an old concept will work in newer frameworks also.
0
 

Author Comment

by:mathieu_cupryk
ID: 22895747
which concept will not work in newer frameworks.
0
 
LVL 12

Accepted Solution

by:
techExtreme earned 500 total points
ID: 22896300
I said it will work in newer frameworks also.
0
 

Author Comment

by:mathieu_cupryk
ID: 22909622
tech if you join
http://ArabLounge.com

What do you think of the setup.

When registering?

when u enter the first page information.

automatically it would be like doing a pc.Save
with membership profile
the second and third ,,, pages.
do they use something like an update.Save

Cross paging is not used in this case?
it would appear that they are passing an id?
storing it in a cookie or session.
what do u think?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now