Export (0) Print
Expand All

ProfileGroupBase.SetPropertyValue Method

Sets the value of a grouped profile property.

Namespace:  System.Web.Profile
Assembly:  System.Web (in System.Web.dll)

Public Sub SetPropertyValue ( _
	propertyName As String, _
	propertyValue As Object _


Type: System.String

The name of the grouped property to set.

Type: System.Object

The value to assign to the grouped property.

ASP.NET uses the ProfileBase class to create the class used for the user profile. When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. Strongly typed accessors are added to the ProfileCommon class for each group and property defined in the profile Element (ASP.NET Settings Schema) configuration section. The strongly typed accessors of the ProfileCommon class call the SetPropertyValue method to pass grouped property values to the ProfileProvider to be stored at the data source.

You can use the SetPropertyValue method to assign values to grouped properties of the user profile for your application by name. Values are typed as object, and type checking will be done at run time, not compile time. For strongly typed access to profile property values, you can access the grouped property by name as a member of a group of the Profile property, for example, Profile.Address.City.

The following ASP.NET page reads and sets the grouped properties specified for the user profile. For an example of a Web.config file that specifies grouped properties for the user profile, see the example provided for the ProfileGroupBase class.

Security noteSecurity Note

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

Public Sub Page_Load()
  If Not IsPostBack Then
    StreetTextBox.Text          = Profile.Address.Street
    CityTextBox.Text            = Profile.Address.City
    StateTextBox.Text           = Profile.Address.State
    CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion
    ZipCodeTextBox.Text         = Profile.ZipCode
  End If
End Sub

Public Sub UpdateButton_OnClick(sender As Object, args As EventArgs)
  Profile.Address.Street          = StreetTextBox.Text
  Profile.Address.City            = CityTextBox.Text
  Profile.Address.State           = StateTextBox.Text
  Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text
  Profile.ZipCode                 = ZipCodeTextBox.Text
End Sub

<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Home Page</title>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
      <td>Street Address</td>
      <td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
      <td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
      <td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
      <td>Zip Code</td>
      <td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
      <td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
  <asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
© 2015 Microsoft