.
, ASP.NET -.
.
:
1. , (, ..)
2. .
3. .
Registration.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="ISP_Sem5.Registration" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="content">
<div id="content_wrapper">
<div class="left">
<div id="style1_gray_border">
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnContinueButtonClick="CreateUserWizard1_ContinueButtonClick"
OnCreatedUser="CreateUserWizard1_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" >
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
<SideBarStyle HorizontalAlign="Center" />
</asp:CreateUserWizard>
</div>
</div>
</div>
</div>
</asp:Content>
Registration.aspx.cs:
public partial class Registration: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Control createUserStepContainer = CreateUserWizard1.FindControl("CreateUserStepContainer");
if(createUserStepContainer!= null)
((TextBox)createUserStepContainer.FindControl("UserName")).MaxLength = Properties.Settings.Default.MaxUserNameLength;
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
Roles.AddUserToRole(CreateUserWizard1.UserName, "user");
}
protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e)
{
Response.Redirect("/default.aspx");
}
}
}
4.
.
ASP.NET.
.
- ( User Control Server Custom Control ). , () , .
|
|
ArticleView.ascx:
<%@ Control Language="C#" AutoEventWireup="true" ViewStateMode="Disabled" CodeBehind="ArticleView.ascx.cs" Inherits="ISP_Sem5.Controls.ArticleView" %>
<asp:ObjectDataSource ID="ObjectArticles" runat="server" SelectMethod="GetNewArticles"
TypeName="ISP_Sem5.BLL.Article">
</asp:ObjectDataSource>
<asp:DataList ID="ArticlesList" runat="server"
EnableTheming="true" DataSourceID="ObjectArticles" DefaultMode="ReadOnly"
GridLines="None" Width="100%" RepeatColumns="3"
onitemdatabound="ArticlesList_ItemDataBound"
ondatabinding="ArticlesList_DataBinding">
<ItemTemplate>
<table cellpadding="6" width="255px">
<tr>
<td style="width: 1px;">
<asp:Label runat="server" ID="CategoryName1" Text='<%# Eval("Title") %>' Font-Size="Medium"
Font-Bold="true" Width="200px" />
<br />
<asp:HyperLink runat="server" ID="lnkCatImage" NavigateUrl='<%# "~/ShowArticle.aspx?ID=" + Eval("ArticleID") %>'>
<div class="image_wrapper">
<asp:Image Width="250px" Height="200px" runat="server" ID="CategoryImage" BorderWidth="0px"
AlternateText='<%# Eval("Title") %>' ImageUrl='<%# Eval("TitleImageURL") %>' />
</div>
</asp:HyperLink>
<br />
<div id="alignRight">
<asp:Button ID="Button2" runat="server" SkinID="GrayButton" CommandName="Edit"
CommandArgument='<%# Eval("ArticleID") %>' Text="Edit" />
<asp:Button ID="Button1" runat="server" SkinID="GrayButton" CommandName="Delete"
CommandArgument='<%# Eval("ArticleID") %>' Text="Delete" />
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
ImageUploader.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImageUploader.ascx.cs" Inherits="ISP_Sem5.Controls.ImageUpload" %>
<asp:FileUpload ID="FileUpload" ViewStateMode="Enabled" runat="server">
</asp:FileUpload>
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" CausesValidation="false" /><br />
<asp:Label ID="lblFeedbackOK" SkinID="FeedbackOK" runat="server"></asp:Label>
<asp:Label ID="lblFeedbackKO" SkinID="FeedbackKO" runat="server"></asp:Label>
Product.ascx:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
|
|
<div class="Product">
<div class="ProductImage"><img alt="<%= Model.Name%>" src="/Content/Images/<%= Model.ImageURL%>" width="119" height="123" border="0" /></div>
<h3><%= Model.Name%></h3>
<div class="Description">
<p><span>:</span> <%= Model.Category.Name%>.<br /></p>
<p><span> :</span> <%= Model.Country.Name%>.<br /></p>
<p><span>:</span> <%= Model.Manufacturer.Name%><br /></p>
<p><span> :</span> <br/><%= Model.Description%></p>
<p><span> :</span> <%= Model.Quantity%> .</p>
<p><span>:</span> <%= Model.Price.ToString("0.00")%>$.</p>
<%= Ajax.ActionLink("", "Order", new {ProductName = Model.Name, Price = Model.Price }, new AjaxOptions { InsertionMode = InsertionMode.InsertAfter, UpdateTargetId = "Basket" })%>
</div>
</div>
5. ASP.NET MVC
:
, ASP.NET MVC.
.
MVC, -, . - ( ). ASP.NET MVC-, , .
, ( ):
1. AJAX, ASP.NET MVC jQuery.
2. .
Display.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderID="SearchContentPlaceHolder" runat="server">
<div class="SearchContainer">
<% Html.BeginForm("Display", "Catalog", FormMethod.Post); %>
: <%= Html.TextBox("ProductName")%>
<% Html.EndForm();%>
</div>
</asp:Content>
<asp:Content ContentPlaceHolderID="leftPanelContentPlaceHolder" runat="server">
<div class="CategoriesMenu">
<% foreach (var Category in (List<e_shop_MVC.Models.Category>)ViewData["Categories"])
{ %>
<%= Html.ActionLink(Category.Name, "Display", new {CategoryID = Category.ID})%><br />
<%
}%>
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="middlePanelContentPlaceHolder" runat="server">
<% foreach (var P in Model)
{
Html.RenderPartial("Product", (e_shop_MVC.Models.Product)P);
}%>
</asp:Content>
CatalogController.cs:
public class CatalogController: Controller
{
DataEntities Data = new DataEntities();
public ActionResult Display(short CategoryID)
{
ViewData.Model = (from P in Data.Product
where P.CategoryID == CategoryID
select P).ToList();
ViewData["Categories"] = Data.Category.ToList();
return View();
}
[HttpPost]
public ActionResult Display(string ProductName)
{
|
|
string Query = "SELECT VALUE A FROM Product AS A WHERE A.Name LIKE('%" + ProductName + "%');";
ViewData.Model = Data.CreateQuery<Product>(Query).ToList();
ViewData["Categories"] = Data.Category.ToList();
return View();
}
public string Order(string ProductName, decimal Price)
{
return ProductName + "-" + Price.ToString("0.00$") + ";<br/>";
}
protected override void Dispose(bool disposing)
{
Data.Dispose();
base.Dispose(disposing);
}
}
6. - WCF
.
- Windows Communication Foundation.
.
- WCF -. , ( ) , WPF- -.
IShopService.cs:
[ServiceContract]
public interface IShopService
{
[OperationContract]
int GetProductsCount();
[OperationContract]
int GetCategoriesCount();
[OperationContract]
List<string> GetProductsNames();
[OperationContract]
List<string> GetCategoriesNames();
}
ShopService.cs:
public class MyShopService: IShopService
{
public int GetProductsCount()
{
int Count = 0;
using(var Context = new DataEntities1())
{
Count = (from P in Context.Product
select P).Count();
}
return Count;
}
public int GetCategoriesCount()
{
int Count = 0;
using (var Context = new DataEntities1())
{
Count = (from P in Context.Category
select P).Count();
}
return Count;
}
public List<string> GetProductsNames()
{
List<string> Names;
using (var Context = new DataEntities1())
{
Names = (from P in Context.Product select P.Name).ToList();
}
return Names;
}
public List<string> GetCategoriesNames()
{
List<string> Names;
using (var Context = new DataEntities1())
{
Names = (from P in Context.Category select P.Name).ToList();
}
return Names;
}
}
7. AJAX
:
AJAX-.
.
-, , AJAX. AJAX AJAX- , .
<script type="text/javascript">
function loadSearchResults() {
$.ajax({
url: 'Catalog/Search?ProductName=' + $('#SearchBox').val(),
success: function (result) {
$('#SearchResults').html(result);
}
});
}
</script>
public ActionResult Search(string ProductName)
{
string Query = "SELECT VALUE A FROM Product AS A WHERE A.Name LIKE('%" + ProductName + "%');";
var Products = Data.CreateQuery<Product>(Query).ToList();
return PartialView(Products);
}