System.Web.UI.PostBackTrigger Sample
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private string saveDir = @"Uploads\"; protected void UploadButton_Click(object sender, EventArgs e) { if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 10000 && !CheckForFileName()) { string savePath = Request.PhysicalApplicationPath + saveDir + Server.HtmlEncode(FileName.Text); //Remove comment from the next line to upload file. //FileUpload1.SaveAs(savePath); UploadStatusLabel.Text = "The file was processed successfully."; } else { UploadStatusLabel.Text = "You did not specify a file to upload, or a file name, or the file was too large. Please try again."; } } protected void CheckButton_Click(object sender, EventArgs e) { if (FileName.Text.Length > 0) { string s = CheckForFileName() ? "exists already." : "does not exist."; UploadStatusLabel.Text = "The file name choosen " + s; } else { UploadStatusLabel.Text = "Specify a file name to check."; } } private Boolean CheckForFileName() { System.IO.FileInfo fi = new System.IO.FileInfo(Request.PhysicalApplicationPath + saveDir + Server.HtmlEncode(FileName.Text)); return fi.Exists; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>PostBackTrigger Example</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> The upload button is defined as a PostBackTrigger.<br/> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <fieldset> <legend>FileUpload in an UpdatePanel</legend> First, enter a file name to upload your file to: <asp:TextBox ID="FileName" runat="server" /> <asp:Button ID="CheckButton" Text="Check" runat="server" OnClick="CheckButton_Click" /> <br /> Then, browse and find the file to upload: <asp:FileUpload id="FileUpload1" runat="server"> </asp:FileUpload> <br /> <asp:Button id="UploadButton" Text="Upload file" OnClick="UploadButton_Click" runat="server"> </asp:Button> <br /> <asp:Label id="UploadStatusLabel" runat="server" style="color:red;"> </asp:Label> </fieldset> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="UploadButton" /> </Triggers> </asp:UpdatePanel> </div> </form> </body> </html>
'ASP.NET AJAX' 카테고리의 다른 글
[ GridView,그리드뷰 ]페이징(page) 디자인 꾸미기 (0) | 2010.06.01 |
---|---|
[ FilterExpression,FilterParameters , 다중검색 ] 두개이상 검색할때... (0) | 2010.06.01 |
[마스터 페이지, masterpage] 에서 유저컨트롤 안에 접근하기 (0) | 2010.06.01 |
[마스터페이지 , masterpage ] PreviousPage 마스터페이지 컨트롤러에 접근 (0) | 2010.06.01 |
[암호화,MD5,SHA1] 비밀번호 암호화 하기 (0) | 2010.06.01 |
엔터키 및 행선택으로 클릭하기 (0) | 2010.06.01 |
MVC 1.0 튜토리얼 PDF 받기 (0) | 2010.03.22 |
[MSDN]AJAX Extensions를 사용한 클라이언트측 웹 서비스 호출 (0) | 2010.02.04 |
템플릿에서의 데이터 바인딩 (0) | 2010.02.04 |
[ .NET 테마(Theme) ,스킨(SKIN)] 적용하기 (0) | 2010.01.13 |