jpweber
  • Posts: 126
  • Joined: 21/03/2012
Hello! It appears to me (I'm not a programmer), but it's really not TOO difficult to add a "Company Name" field to the registration page. Could someone please correct me if I'm wrong, but if I went to pages/register.ascx, and, for instance, after this code:

Quote:

-tr- Email field table row -/tr-



Just literally put another table row after this, such as:

Quote:

-tr- Company Name table row -/tr-



And just replace all the "Email" verbage with "Company" verbage (i.e. "Email is required", change to "Company name is required" )

Then comes the difficult part. I'd have to add some type of field or fields to the database. I'm terrible with databases, but basically, wherever I see an email field in the database, I'll just create a company field.

Could anybody tell me if my thinking is correct, or if it won't work, before I start actually doing this? Thanks!
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
Thantis
  • Posts: 86
  • Joined: 04/08/2011
I don't know all the steps, but I am pretty sure you would have to add a new column in a couple tables in your database first.
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Thanks, Thantis. I'm pretty sure I can handle the asp page coding to add another field, such as Company Name.

The problem is with databases. Do you, by any chance, know where I'd find the proper tables for the registration page? I have My SQL Server Management Studio open, but I'm afraid to tinker with it (although I already made a backup) until I'm more confident in determining which tables I should be looking for, or where to find 'em.

If you have any idea about this, it'd be great if you could share. Or, I could start another post and try to ask a database guru .... lol

Thanks again Thantis,

Jason Weber
USS Vision Inc.
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
tha_watcha
  • Posts: 4045
  • Joined: 06/03/2010
No sorry it is not that easy currently to add new Profile Fields, in the future releases maybe there will a better solution for that Problem.

Currently its not enough to simply add a new Column to the Profile Table, you also need to change the source code, in order to correctly load and save the new Profile Fields.

Are you able to Recompile YAF inside Visual Studio? If yes i could show how to add new fields.


UserPostedImage
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Hi tha_watcha.

Yes, I'm using Visual Studio 2010 Ultimate for everything, including all editing within YAF.

I have the Microsoft SQL Server Management Studio for database management, and that's where I'm really lost.

So that's where I'm at!

I'm definitely open to any suggestions you might have, as I want to add a "Company Name" and "Phone Number" field, and I hope they're not too difficult! lol ... As I mentioned, I have VS 2010 and I'm pretty good with it -- so as when you suggest "recompile" the source code, I just have to edit it -- not recreate it all over again! lol

Thanks again for trying to help!
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Yes, the Watcha, I am able to view everything w/ Visual Studio 2010 Ultimate ... .using YAF 1.95 but I really need to add 2 more fields to the registration page --- company name, and company phone ....

If you could help in any way, it would be truly appreciated!
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
tha_watcha
  • Posts: 4045
  • Joined: 06/03/2010
Originally Posted by: jpweber

Yes, the Watcha, I am able to view everything w/ Visual Studio 2010 Ultimate ... .using YAF 1.95 but I really need to add 2 more fields to the registration page --- company name, and company phone ....

If you could help in any way, it would be truly appreciated!




Sorry i dont have much time but i didnt forget you here is a little how to add 2 new Profile Fields. I tested it with YAF 1.96.1 but i also should work in 1.95. (In your Version its YAF.Classes.Utils instead of YAF.Utils also YAF.Classes.Core

First Create the Profile Fields in the Provider:

File YAF.Utils\YafUserProfile.cs

/// <summary>
    /// Gets or sets the Company Name.
    /// </summary>
    [SettingsAllowAnonymous(false)]
    [CustomProviderData("CompanyName;nvarchar;255")]
    public string CompanyName
    {
        get
        {
            return base["CompanyName"] as string;
        }

        set
        {
            base["CompanyName"] = value;
        }
    }

    /// <summary>
    /// Gets or sets the Company Phone.
    /// </summary>
    [SettingsAllowAnonymous(false)]
    [CustomProviderData("CompanyPhone;nvarchar;255")]
    public string CompanyPhone
    {
        get
        {
            return base["CompanyPhone"] as string;
        }

        set
        {
            base["CompanyPhone"] = value;
        }
    }


And also to the Interface in

File: YAF.Types\Interfaces\IYafUserProfile.cs

    /// <summary>
    /// Gets or sets the Company Name.
    /// </summary>
    string CompanyName { get; set; }

    /// <summary>
    /// Gets or sets the Company Phone.
    /// </summary>
    string CompanyPhone { get; set; }


Add the New Field to the Register Page after Homepage

File: ..\pages\register.ascx


<tr>

  <td align="right" class="postheader">

  <asp:Label ID="HomepageLabel" runat="server" AssociatedControlID="Homepage">
  <YAF:LocalizedLabel ID="LocalizedLabel13" runat="server" LocalizedTag="HOMEPAGE" />:</asp:Label>
</td>
<td class="post">
  <asp:TextBox ID="Homepage" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="postheader">
<asp:Label ID="CompanyNameLabel" runat="server" AssociatedControlID="Homepage">
<YAF:LocalizedLabel ID="LocalizedLabel19" runat="server" LocalizedTag="COMPANYNAME" />
									:</asp:Label></td>
<td class="post">
<asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="postheader">
<asp:Label ID="CompanyPhoneLabel" runat="server" AssociatedControlID="Homepage">
<YAF:LocalizedLabel ID="LocalizedLabel20" runat="server" LocalizedTag="COMPANYPHONE" />
									:</asp:Label></td>
<td class="post">
  <asp:TextBox ID="CompanyPhone" runat="server"></asp:TextBox>
</td>
</tr>


Also edit the register.ascx.cs

var homepageTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("Homepage");
        var companyNameTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("CompanyName");
        var companyPhoneTextBox = (TextBox)this.CreateUserWizard1.FindWizardControlRecursive("CompanyPhone");
        var dstUser = (CheckBox)this.CreateUserWizard1.FindWizardControlRecursive("DSTUser");


and

userProfile.Homepage = homepageTextBox.Text.Trim();
userProfile.CompanyName = companyNameTextBox.Text.Trim();
userProfile.CompanyPhone = companyPhoneTextBox.Text.Trim();


Now if you want to allow the user to edit this Properties

Add the new fields to the ..\controls\EditUserProfile.ascx

<tr>
<td colspan="2" class="header2">
<b><YAF:LocalizedLabel ID="LocalizedLabel8" runat="server" LocalizedPage="CP_EDITPROFILE" LocalizedTag="companyname" />
</b>
</td>
</tr>
<tr>
<td class="postheader">
<YAF:LocalizedLabel ID="LocalizedLabel9" runat="server" LocalizedPage="CP_EDITPROFILE"
                LocalizedTag="companyname2" />
 </td>
<td class="post">
<asp:TextBox runat="server" ID="CompanyName" CssClass="edit" />
 </td>
</tr>
<tr>
<td colspan="2" class="header2">
<b>
<YAF:LocalizedLabel ID="LocalizedLabel8" runat="server" LocalizedPage="CP_EDITPROFILE"
                    LocalizedTag="companyphone" />
 </b>
</td>
</tr>
<tr>
<td class="postheader">
<YAF:LocalizedLabel ID="LocalizedLabel9" runat="server" LocalizedPage="CP_EDITPROFILE"
                LocalizedTag="companyphone" />
</td>
<td class="post">
<asp:TextBox runat="server" ID="CompanyPhone" CssClass="edit" />
</td>
</tr>


And load and save this fields in the EditUsersProfile.ascx.cs

this.HomePage.Text = this.UserData.Profile.Homepage;
this.CompanyName.Text = this.UserData.Profile.CompanyName;
this.CompanyPhone.Text = this.UserData.Profile.CompanyPhone;


and

userProfile.CompanyName = this.CompanyName.Text.Trim();
userProfile.CompanyPhone = this.CompanyPhone.Text.Trim();


The loading and saving is done now you may want to show this to field in the user Profile Page. ..\pages\profile.ascx

<tr runat="server" id="TwitterTR" visible="false">
<td class="postheader">
<YAF:LocalizedLabel ID="LocalizedLabel25" runat="server" LocalizedTag="Twitter" />
</td>
<td class="post">
<asp:Label ID="lbltwitter" runat="server" />
</td>
</tr>
<tr runat="server" id="CompanyNameTR" visible="false">
<td class="postheader">
<YAF:LocalizedLabel ID="LocalizedLabel30" runat="server" LocalizedTag="CompanyName" />
</td>
<td class="post">
<asp:Label ID="lblCompanyName" runat="server" />
</td>
</tr>
<tr runat="server" id="CompanyPhoneTR" visible="false">
<td class="postheader">
<YAF:LocalizedLabel ID="LocalizedLabel31" runat="server" LocalizedTag="CompanyPhone" />
</td>
<td class="post">
<asp:Label ID="lblCompanyPhone" runat="server" />
</td>
</tr>


and

the profile.ascx.cs

if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Twitter))
            {
                this.TwitterTR.Visible = true;
                this.lbltwitter.Text = this.HtmlEncode(this.Get<IBadWordReplace>().Replace(userData.Profile.Twitter));
            }

            if (this.User != null && !string.IsNullOrEmpty(userData.Profile.CompanyName))
            {
                this.CompanyNameTR.Visible = true;
                this.lblCompanyName.Text = this.HtmlEncode(this.Get<IBadWordReplace>().Replace(userData.Profile.CompanyName));
            }

            if (this.User != null && !string.IsNullOrEmpty(userData.Profile.CompanyPhone))
            {
                this.CompanyPhoneTR.Visible = true;
                this.lblCompanyPhone.Text = this.HtmlEncode(this.Get<IBadWordReplace>().Replace(userData.Profile.CompanyPhone));
            }


And finally add the new language strings to the …/languages/english.xml

<Resource tag="HOMEPAGE">Home Page</Resource>
      <Resource tag="HOMEPAGE2">Your Web Site (public):</Resource>
     <Resource tag="COMPANYNAME">Company Name</Resource>
     <Resource tag="COMPANYPHONE">Company Phone</Resource>
          <Resource tag="COMPANYNAME2">The Name of your Company:</Resource>
     <Resource tag="COMPANYPHONE2">Your Company Phone Number:</Resource>


If I don’t forget something you need to compile and you should have to new Profile Properties.
UserPostedImage
bbobb
  • Posts: 1558
  • Joined: 21/10/2008
Technically, several 'wild card' fileds can be added as binaries or text in T-SQL like field1, field2 and names for them can be put in host settings as a delimited string with data types too. After this even a UI can be made to add a limited number of fields.
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Wow, tha_watcha .... that was a ton of information, but I'm going to do it all; your instructions were quite clear.

Are you sure I don't have to do anything with the database? You didn't mention anything about adding fields to the database, which would be the tough part for me.

All of the coding you provided was intricate, but I can handle that part of things.

Thank you again for taking all of the time you did to help me add a couple of new fields!
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
tha_watcha
  • Posts: 4045
  • Joined: 06/03/2010
Originally Posted by: jpweber

Are you sure I don't have to do anything with the database? You didn't mention anything about adding fields to the database, which would be the tough part for me.



The Fields are added automatically in to the asp net profile.

UserPostedImage
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Hey tha-watcha!

Those instructions were unbelievable! I followed all of them easily -- they were clear! The only thing I found was that YAF.Core\Interfaces\IYafUserProfile.cs is actually in YAF.Types, but that was easy to figure out.

Everything looks great now in 1.96. The fields are all there or Company Name and Company Phone when you register -- and they're there when you view the member profile.

The only problem is that when you register and fill out your Company Name or Phone, it doesn't actually show up. So on the member profile page, there's a field for "Company Name:" but it shows up blank.
or
When you go to edit your profile, there's a place there to input your company name and phone again, but when you save it, the field shows up blank again.

I've labored for hours over this, and the attached image is the only thing I can find weird in Visual Studio:
1) In pages/register.ascx.cs VS keeps telling me that companyname and phone aren't in YAF.Utils/YafUserProfile (but this isn't true -- it's defined just like you told me!)

2) In controls/EditUsersProfile.ascx.cs, VS keeps telling me that companyname and phone aren't in YAF.Types/Interfaces/IYafUserProfile (this isn't true; it's defined just like you told me!)

I can't thank you enough for the time you've taken to help me out on this. If you can possibly help me out with this last issue, it'd be truly appreciated.
jpweber attached the following image(s):

Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
tha_watcha
  • Posts: 4045
  • Joined: 06/03/2010
Did you recompile the whole solution, or just one project?

You need to make sure that all dlls are recompiled, and your reference problem should be solved.
UserPostedImage
jpweber
  • Posts: 126
  • Joined: 21/03/2012
tha_watch, all I know is that I took that folder, my YAF folder, /knowledgebase/ and I went in VS, and I clicked Build ----> Build Website .... and it finally built successfully ...

Although the new fields still locally showed, they didn't work .... I uploaded all the .dll files over again, and they didn't make a difference .... still the same, where the person can fill out their company name or company phone, and it doesn't show up.

Thanks Watcha .. you got the fields for companyname and companyphone to show up ... but Any suggestions you might have would be greatly appreciated! If you want any logins or passwords, just let me know ...
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
tha_watcha
  • Posts: 4045
  • Joined: 06/03/2010
Are you sure you modified or files correctly? It works on my test site.

Did you modified the EditUserProfile.ascx.cs and register.ascx.cs correctly?

I attached both files
File Attachment(s):
EditUsersProfile.ascx.cs (32kb) downloaded 57 time(s).
register.ascx.cs (29kb) downloaded 54 time(s).

UserPostedImage
jpweber
  • Posts: 126
  • Joined: 21/03/2012
Hi tha_watcha ....

Maybe it's because I keep my dlls in the /bin/ and web.config, etc., in my /knowledgebase/ directory, not the root of my website.

Our edituserprofile.ascx.cs files were slightly different (in another area) and our register.ascx.cs files were identical (compared them using Winmerge). I uploaded both, but there was no change. Again, all of the fields that came with 1.96 SRC work perfectly; it's only the two fields that we created that still won't work.

It's like when you enter your company name in the textbox, it doesn't get registered in the database or something.

Thank you very much for taking the time to send me those files! Any other recommendations you might have would be again, greatly appreciated, when you have the time.

Maybe it's because when I build the website in VS, I just opened up the /knowledgebase/ directory as a website, and built that. As I mentioned, I keep the dlls in my /bin/ and web.config, db.config, etc., in my /knowledgebase/ directory -- not in my root. That's how I did it in YAF 1.95 also. And everything functions fine, except for the new fields. But maybe if I built my website right from the root, it might make a difference?

Thanks again for all your help!
Jason Weber
USS Vision YAF 
"Money is better than poverty, if only for financial reasons"
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved