Merhaba
arkadaşlar bu makalemizde asp.net te profil kullanımı örneği yapacağız.
web.config
dosyasına
<profile>
<properties>
<add name="Name" type ="String"/>
<add name="Birthday" type ="System.DateTime"/>
<group name="Address">
<add name="Street"/>
<add name="City"/>
<add name="State"/>
<add name="Zipcode"/>
</group>
</properties>
</profile>
Ekleyin.
Screenshot
Şekil
1
Şekil
2
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);
if
(pc != null)
{
this.txtname.Text = pc.Name;
this.txtaddr.Text = pc.Address.Street;
this.txtcity.Text = pc.Address.City;
this.txtstate.Text = pc.Address.State;
this.txtzip.Text = pc.Address.Zipcode;
this.Calendar1.SelectedDate = pc.Birthday;
}
}
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);
if (pc != null)
{
pc.Name = this.txtname.Text;
pc.Address.Street = this.txtaddr.Text;
pc.Address.City = this.txtcity.Text;
pc.Address.State = this.txtstate.Text;
pc.Address.Zipcode = this.txtzip.Text;
pc.Birthday = this.Calendar1.SelectedDate;
Label1.Text = "Profil başarılı bir
şekilde kaydedildi!"
+
"
Ad ve Soyad: " + pc.Name +
Ad ve Soyad: " + pc.Name +
"
Adres: " + pc.Address.Street +
Adres: " + pc.Address.Street +
"
Şehir: " + pc.Address.City +
Şehir: " + pc.Address.City +
"
Ülke: " + pc.Address.State +
Ülke: " + pc.Address.State +
"
Kod: " + pc.Address.Zipcode +
Kod: " + pc.Address.Zipcode +
"
Doğum Tarihi: " + pc.Birthday ;
Doğum Tarihi: " + pc.Birthday ;
pc.Save();
}
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server" Text="Ad Soyad" AssociatedControlID="txtname"></asp:Label>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Adres" AssociatedControlID="txtaddr"></asp:Label>
<asp:TextBox ID="txtaddr" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Şehir" AssociatedControlID="txtcity"></asp:Label>
<asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="Ülke" AssociatedControlID="txtstate"></asp:Label>
<asp:TextBox ID="txtstate" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label6" runat="server" Text="Kod" AssociatedControlID="txtstate"></asp:Label>
<asp:TextBox ID="txtzip" runat="server"></asp:TextBox>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
<br />
<asp:Button ID="btn1" runat="server" Text="Profil Ekle" OnClick="btnsubmit_Click" />
</div>
</form>
</body>
</html>
Bir makalenin daha sonuna geldik. Bir sonraki makalede
görüşmek üzere. Bahadır ŞAHİN
0 comments:
Yorum Gönder