Ciao a tutti,
Ho la necessita' che la mia applicazione con un click su un determinato button apra una nuova finestra in cui c'e' un campo per "uplodare" un file. Per fare questo ho seguito la linea guida in PopUp Calendar che riporto giu per comodita' (Parent Page):Mentre il child window e':codice:<%@ Page Language="VB" %> <script runat="server"> </script> <html> <head> <script language="Javascript"> function GetDate(CtrlName) { ChildWindow = window.open('Calendar.aspx?FormName=' + document.forms[0].name + &CtrlName=' + CtrlName, "PopUpCalendar", width=270,height=300,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no"); } function CheckWindow() { ChildWindow.close(); } </script> </head> <body onUnload="CheckWindow();"> <form runat="server"> Start Date: <asp:TextBox id="txtStartDate" runat="server"></asp:TextBox> [img]../Images/SmallCalendar.gif[/img] End Date: <asp:TextBox id="txtEndDate" runat="server"></asp:TextBox> [img]../Images/SmallCalendar.gif[/img] </form> </body> </html>ma il problema che incontro io e' che mentre nel popup calendar io ho l'eventocodice:<%@ Page Language="VB" %> <script runat="server"> Public strFormName As String Public strCtrlName As String Public strSelectedDate As String Sub Page_Load(Sender As Object, E As EventArgs) If Not IsPostBack Then '------------------------------------------------------------------- ' Set the Calendar to Today's date in the first load '------------------------------------------------------------------- myCalendar.SelectedDate = System.DateTime.Now() '------------------------------------------------------------------- ' Set the DropDownList of Month and Year to Current Month and Year '------------------------------------------------------------------- ddlMonth.Items.FindByValue(DateTime.Now.Month).Selected = True ddlYear.Items.FindByValue(DateTime.Now.Year).Selected = True End If '------------------------------------------------------------------- ' Set the Selected Date to a temp String ' Set FormName and Control Name to 2 String from the values in QueryString '------------------------------------------------------------------- strSelectedDate = myCalendar.SelectedDate.ToString("dd/MM/yyyy") strFormName = Request.QueryString("FormName") strCtrlName = Request.QueryString("CtrlName") End Sub Sub myCalendar_SelectionChanged(sender As Object, e As EventArgs) '------------------------------------------------------------------- ' Change the Temp Selected Date Object if change is made '------------------------------------------------------------------- strSelectedDate = myCalendar.SelectedDate.ToString("dd/MM/yyyy") End Sub Sub ddl_SelectedIndexChanged(Sender As Object, e As EventArgs) '------------------------------------------------------------------- ' Change the VisibleDate of the Calendar according to ' the DropDownList dynamically '------------------------------------------------------------------- myCalendar.VisibleDate = New DateTime(CInt(ddlYear.SelectedItem.Value), CInt(ddlMonth.SelectedItem.Value), 1) End Sub </script> <html> <head> <script language="Javascript"> function ReturnDate() { window.opener.document.forms["<%= strFormName %>"].elements["<%= strCtrlName %>"].value = "<%= strSelectedDate %>"; window.close(); } function Close() { window.close(); } </script> </head> <body> <form runat="server"> <table> <tr> <td align="Center"> Month: <asp:DropDownList id="ddlMonth" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem Value="1">January</asp:ListItem> <asp:ListItem Value="2">February</asp:ListItem> <asp:ListItem Value="3">March</asp:ListItem> <asp:ListItem Value="4">April</asp:ListItem> <asp:ListItem Value="5">May</asp:ListItem> <asp:ListItem Value="6">June</asp:ListItem> <asp:ListItem Value="7">July</asp:ListItem> <asp:ListItem Value="8">August</asp:ListItem> <asp:ListItem Value="9">September</asp:ListItem> <asp:ListItem Value="10">October</asp:ListItem> <asp:ListItem Value="11">November</asp:ListItem> <asp:ListItem Value="12">December</asp:ListItem> </asp:DropDownList> Year: <asp:DropDownList id="ddlYear" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem Value="2001">2001</asp:ListItem> <asp:ListItem Value="2002">2002</asp:ListItem> <asp:ListItem Value="2003">2003</asp:ListItem> <asp:ListItem Value="2004">2004</asp:ListItem> <asp:ListItem Value="2005">2005</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td align="Center"> <asp:Calendar id="myCalendar" runat="server" BorderWidth="1px" BackColor="#FFFFCC" Width="220px" DayNameFormat="FirstLetter" ForeColor="#663399" Height="200px" Font-Size="8pt" Font-Names="Verdana" BorderColor="#FFCC66" ShowGridLines="True" OnSelectionChanged="myCalendar_SelectionChanged"> <SelectorStyle backcolor="#FFCC66"></SelectorStyle> <NextPrevStyle font-size="9pt" forecolor="#FFFFCC"></NextPrevStyle> <DayHeaderStyle height="1px" backcolor="#FFCC66"></DayHeaderStyle> <SelectedDayStyle font-bold="True" backcolor="#CCCCFF"></SelectedDayStyle> <TitleStyle font-size="9pt" font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></TitleStyle> <OtherMonthDayStyle forecolor="#CC9966"></OtherMonthDayStyle> </asp:Calendar> </td> </tr> <tr> <td align="Center"> <input id="btnReturnDate" onclick="Javascript:ReturnDate()" type="button" value="Select" runat="Server" /> <input id="btnCloseWindow" onclick="Javascript:Close()" type="button" value="Close" runat="Server" /> </td> </tr> </table> </form> </body> </html>mentre per il fileUpload non ho nessuno evento che mi permetta di aggiornare dinamicamente il valore selezionato.codice:OnSelectionChanged
Vi posto anche il mio codice (solo la parte della popup window)Code behind:codice:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChangeImage.aspx.cs" Inherits="hr_company_ee_ChangeImage" %> <!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>ThirdForce Intranet Service</title> </head> <body> <form id="form1" runat="server"> <div class="divBody"> <asp:Label ID="Label1" runat="server" CssClass="subTitle" Text="Change image"></asp:Label> <asp:FileUpload ID="FileUpload1" runat="server" CssClass="textBox" /> <asp:Label ID="Label2" runat="server" CssClass="subTitle"></asp:Label> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%"> <tr> <td style="width: 100px"> <asp:Button ID="Button1" runat="server" CssClass="button" OnClick="Button1_Click" Text="Upload" /></td> <td style="width: 100px"> <asp:Button ID="Button2" runat="server" CssClass="button" Text="Close" /></td> <td style="width: 100px"> </td> <td style="width: 100px"> </td> </tr> </table> </div> </form> </body> </html>
Come posso risolvere il problema?codice:public partial class hr_company_ee_ChangeImage : System.Web.UI.Page { public string fileName; protected void Page_Load(object sender, EventArgs e) { String script = "<script type=\"text/javascript\"> "; script += "<!-- \n"; script += "function load(){\n "; script += "window.opener.document.forms['form1'].elements['Label1'].value=" + fileName + "; \n "; script += "}"; script += "\n// --> "; script += "</script>"; Page.RegisterStartupScript("load", script); } private string uploadPicture() { Stream imgStream = FileUpload1.PostedFile.InputStream; int imgLen = FileUpload1.PostedFile.ContentLength; fileName = FileUpload1.FileName; byte[] imgBinaryData = new byte[imgLen]; int n = imgStream.Read(imgBinaryData, 0, imgLen); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(imgBinaryData); }
Thanks


Rispondi quotando