FBEvo1
FBEvo1

Reputation: 61

Asp.net Membership Profile FirstName and LastName (Not declared. It may be inaccessible due to its protection level )

When i created a profile and when i add items it always says not declared in the code behind!!

I tried to change the Framework of the project from Framework 4.0 to Framework 3.5 and it still didn't work.

It says FirstNamep , LastNamep are not declared .

And in the Web.config :

   <profile defaultProvider="CustomProfileProvider" enabled="true">

   <providers>

  </providers>

  <!-- Define the properties for Profile... -->
  <properties>
      <add name="FirstNamep" type="String" />
      <add name="LastNamep" type="String" />

  </properties>
</profile>

Behind the Code:

    Profile.FirstNamep = FirstNameTextBox.Text 
    Profile.LastNamep = LastNameTextBox.Text

Upvotes: 2

Views: 1282

Answers (1)

McGarnagle
McGarnagle

Reputation: 102743

The properties are dynamically generated at runtime, which means you can't access them from code-behind. What you can do is access them from your .ASPX pages using a script block (if that works for you). Like this.

<%@ Page Language="C#" %>

<script runat="server">
    public void Page_Init()
    {
        Profile.FirstNamep = "some dood";
    }
</script>

<div>Your name is <%= Profile.FirstNamep %></div>

It seems to be sort of "by design" that the Profile is available to .aspx pages, but not to the code behind.


If you've defined the default provider as CustomProfileProvider, then that has to be a class that inherits System.Web.Profile.ProfileProvider. Otherwise, you should use the default SQL profile provider.

<connectionStrings>
   <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>

<membership>
    <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>

   

Upvotes: 0

Related Questions