Hvorfor åbnes et nyt vindue ved PostBack?
Hver gang der køres en postback på siden åbner skidtet en ny side. Er der nogen der kan fortælle mig hvorfor?Siden er ikke færdigudviklet, for den er ikke til at arbejde med når den hele tiden åbner et nyt vindue...
Her følger koden med HTML:
<%@ Page language="c#" Codebehind="uploadOgSkaler.aspx.cs" AutoEventWireup="false" Inherits="London.uploadOgSkaler" %>
<HTML>
<HEAD>
<title>Upload et billede</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" target="_blank" encType="multipart/form-data" runat="server">
<p><asp:DropDownList ID="kategoriValg" AutoPostBack="True" Runat="server" DataValueField="k_id" DataTextField="k_navn" ForeColor="black" OnSelectedIndexChanged="setP"></asp:DropDownList></p>
<p>Vælg en fil: <input id="File1" type="file" maxLength="30" name="File1" runat="server">
<asp:requiredfieldvalidator id="RequiredFieldValidator" runat="server" Width="100%" Display="Dynamic" ControlToValidate="File1"> Du skal vælge et billede før du kan uploade!</asp:requiredfieldvalidator></p>
<P><asp:radiobuttonlist id="Scaling" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">1x</asp:ListItem>
<asp:ListItem Value="2">½x</asp:ListItem>
<asp:ListItem Value="4" Selected="True">1/4 x</asp:ListItem>
</asp:radiobuttonlist><br>
Indtast et filnavn: <asp:TextBox ID="FileName" Runat="server"></asp:TextBox></P>
<P><span id="Span1" style="FONT: 8pt verdana; COLOR: red" runat="server"><br><br>
<input id="Button1" type="submit" value="Upload og skaler" name="Button1" runat="server" OnServerClick="Button1_Click"></span>
<asp:Label ID="uploadRapport" Runat="server"></asp:Label></P>
</form>
</body>
</HTML>
og her koden:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Text.RegularExpressions;
using Microsoft.Data.Odbc;
namespace London
{
/// <summary>
/// Summary description for uploadOgSkaler.
/// </summary>
public class uploadOgSkaler : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.WebControls.RadioButtonList Scaling;
protected System.Web.UI.HtmlControls.HtmlGenericControl Span1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator;
protected System.Web.UI.WebControls.Label uploadRapport;
protected System.Web.UI.HtmlControls.HtmlInputButton Button1;
protected System.Web.UI.WebControls.Button NyKnap;
protected System.Web.UI.WebControls.TextBox FileName;
public string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["MDBString"];
protected System.Web.UI.WebControls.DropDownList kategoriValg;
private void Page_Load(object sender, System.EventArgs e)
{
databind_getKategori()
}
bool ServerValidation()
{
Regex r = new Regex(".*\\.(jpg|gif|png)$", RegexOptions.IgnoreCase|RegexOptions.Compiled);
return r.IsMatch(File1.PostedFile.FileName);
}
protected void Button1_Click(object Source, EventArgs e)
{
if (File1.PostedFile != null)
{
if(ServerValidation())
{
try
{
Bitmap BitmapSource = new Bitmap(File1.PostedFile.InputStream);
int ScaleValue = Int32.Parse(Scaling.SelectedItem.Value);
int DestWidth = BitmapSource .Width / ScaleValue;
int DestHeight = BitmapSource.Height/ScaleValue;
Bitmap BitmapDest = new Bitmap(DestWidth,DestHeight);
Graphics bmpGraphics = Graphics.FromImage(BitmapDest);
// set Drawing Quality
bmpGraphics.InterpolationMode = InterpolationMode.High;
string strFileName = FileName.Text;
strFileName += ".jpg";
Rectangle compressionRectangle = new Rectangle(0, 0, DestWidth, DestHeight);
bmpGraphics.DrawImage(BitmapSource, compressionRectangle);
//BitmapDest.Save(Server.MapPath("upload/oel/"+strFileName), ImageFormat.Jpeg);
}
catch (Exception exc)
{
Span1.InnerHtml = "Error Uploading file <b>" + exc.ToString();
}
}
else
{
RequiredFieldValidator.Text = "<br> Vælg en fil af typen jpg, gif eller png<br>";
}
}
}
protected void databind_getKategori()
{
try
{
OdbcConnection Conn = new OdbcConnection(ConnStr);
Conn.Open();
string SQL = "SELECT * FROM `kategori` ORDER BY `k_navn` ASC";
OdbcCommand Cmd = new OdbcCommand();
Cmd.CommandText = SQL;
Cmd.Connection = Conn;
kategoriValg.DataSource = Cmd.ExecuteReader();
kategoriValg.DataBind();
kategoriValg.Items.Insert(0, "-- Vælg en kategori --");
}
catch(Exception fejl)
{
Response.Write(fejl.Message);
}
}
protected void setP(object Sender, EventArgs e)
{
uploadRapport.Text = "hej";
}