Bonjour,
Je veux ouvrir un alert popup dans quelques conditions.
Je upload fichiers de différents categorie(excel,video,word.....)
Mais je veux ouvrir popup uniquement lorsque je upload word.
Comment peut on faire?
Version imprimable
Bonjour,
Je veux ouvrir un alert popup dans quelques conditions.
Je upload fichiers de différents categorie(excel,video,word.....)
Mais je veux ouvrir popup uniquement lorsque je upload word.
Comment peut on faire?
Essaye cette solution :
Si tu as d'autre souci n'hésite pas.Code:
1
2
3
4
5
6
7
8
9
10
11
12 if (FileUpload1.HasFile) { string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName); if (fileExt == ".doc") { string popupScript = "<script language='javascript'>" +"window.open('PopUp.aspx', 'CustomPopUp', " +"'width=200, height=200, menubar=yes, resizable=no')" +"</script>"; Page.RegisterStartupScript("PopupScript", popupScript); } }
bonne courage ;)
d'ou il faut mettre?
dans aspx ou aspx.cs?
c'est dans le CodeBehind c-a-d ".cs" au niveau de ton contrôle, voilà un petit exemple :
Page Default.aspx :
Pages Default.aspx.cs :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <%@ 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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /> </div> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </form> </body> </html>
Il faut pas oublié de crée ta page "Popup.aspx" ou bien changer le nom vers la page que tu veux ;)Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName); if (fileExt == ".doc" || fileExt == ".docx") { string popupScript = "<script language='javascript'>" +"window.open('PopUp.aspx', 'CustomPopUp', " +"'width=200, height=200, menubar=yes, resizable=no')" +"</script>"; Page.RegisterStartupScript("PopupScript", popupScript); } } } }
Bonne courage ;)