Validation : (Điều khiển kiểm tra dữ liệu)
- Dùng để kiểm tra tính hợp lệ của dữ liệu.
- Tự động phát sinh code kiểm tra dữ liệu ở client-side tùy thuộc và webBrowser có hỗ trợ thực thi script ở clieng không.
Giới hạn file trong fileupload :
- Hạn chế những file không cần thiết khi upload lên server.
- Kiểm tra nhanh chóng tại client (bạn nên kiểm tra ở server nữa).
Demo : chỉ được upload những file nhu : rar,doc,pdf,excell,powpoint
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hoclaptrinhweb.com chia sẽ là niềm vui</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fileuploadDocument" runat="server" /><asp:RegularExpressionValidator
ID="revFileuploadDocument" runat="server" ControlToValidate="fileuploadDocument"
Display="Dynamic" ErrorMessage="chỉ được upload những file nhu : rar,doc,pdf,excell,powpoint"
ValidationExpression="^.*\.(xls|XLS|ppt|PPT|doc|DOC|pdf|PDF|rar|RAR|zip|ZIP)$"></asp:RegularExpressionValidator>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" /> </div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hoclaptrinhweb.com chia sẽ là niềm vui</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fileuploadDocument" runat="server" /><asp:RegularExpressionValidator
ID="revFileuploadDocument" runat="server" ControlToValidate="fileuploadDocument"
Display="Dynamic" ErrorMessage="chỉ được upload những file nhu : rar,doc,pdf,excell,powpoint"
ValidationExpression="^.*\.(xls|XLS|ppt|PPT|doc|DOC|pdf|PDF|rar|RAR|zip|ZIP)$"></asp:RegularExpressionValidator>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" /> </div>
</form>
</body>
</html>
Comments[ 0 ]
Đăng nhận xét