Witam,
proszę o pomoc w następującym problemie. Posiadam kod napisany w javascript, który mi wyświetla dialog z text boxem, image, file uploadem i 2 guzikami. Udało mi się już wyświetlanie miniaturki w image wybranej przez file upload. Teraz chcę zrobić upload image na serwer po naciśnięciu przez 1 z guzikowa, a następnie zamkniecie dialogu. zamkniecie dialogu wiem jak zrobić, lecz nie mam pojęcia jak zrobić ten file upload. Proszę o pomoc. Oto kod który do tej pory napisałem:
<%@ Page Title="" Language="C#" MasterPageFile="~/MenuAdmin.master" AutoEventWireup="true" CodeBehind="kategoirie.aspx.cs" Inherits="WebApplication1.WebForm6" %>
<asp:Content ID="Content1" ContentPlaceHolderID="nastedmainHead" runat="server">
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css ">
<script type="text/javascript" src="https://code.jquery.com/jquery.js "></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.10.4/jquery-ui.js "></script>
<script type="text/javascript">
var path = null;
var name = null;
var filePath = null;
$(document).ready(function ()
{
$("#def-dialog").click(function ()
{
$("#dodaj_kategorie").dialog(
{
resizable: false,
width: '40%',
modal: true,
title: "Dodaj kategorie",
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "blind",
duration: 1000
}
});
});
});
function showimagepreview(input) {
if (input.files && input.files[0]) {
var filerdr = new FileReader();
path = input.files[0];
filerdr.onload = function (e) {
$('#<%=Image1.ClientID%>').attr('src', e.target.result);
}
filerdr.readAsDataURL(input.files[0]);
}
}
function nameGet(e) {
name = e.value;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="nastedmain" runat="server">
<div id="dodaj_kategorie" style="display: none;">
<div class="wprowadzTytul">
<asp:Panel ID="Panel1" runat="server" style="width:100%;display: table-cell;"><br /><br />
<div class="wprowadzTytul"style="margin-left: 5%;">
Wprowadź nazwę kategorii:
</div>
<div class="TextBoxtytul" style="margin-left: 5%; width:100%">
<asp:TextBox ID="TextBoxTytul" CssClass="form-control" runat="server" onchange="nameGet(this)"></asp:TextBox>
</div>
<div class="Validacja" style="width: 90%; text-align:left">
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Wprowadz nazwe kategorii" ControlToValidate="TextBoxTytul" Display="Dynamic" Font-Size="10px" ForeColor="Red" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</div>
<asp:Panel ID="Panel2" runat="server" style="width:30%; margin-left: 10%; display: inline;">
Dodaj ikone:
<div style="width:90%; display: flex; margin:auto;" >
<asp:Label ID="LabelZdjecie1" runat="server" Width="102" BorderStyle="Solid" style="text-align:center; margin-left:10%;">
<asp:Image ID="Image1" runat="server" Width="100%"/>
</asp:Label>
<div class="wczytywanie" style="margin-left:1%;">
<asp:FileUpload ID="FileUploadImage1" Width="80%" Height="20px" runat="server" Font-Size="10px" onchange="showimagepreview(this)" />
</div>
<br /><br />
</div>
</asp:Panel>
<br />
<div id="guzik_zaloguj">
<button id="btnsave" class="btn btn-default">Save</button>
<asp:Button ID="Button1" runat="server" type="button" class="btn btn-default" Text="Dodaj" OnClientClick="Button1_Click"/>
<asp:Button ID="Button2" runat="server" type="button" class="btn btn-default" Text="Anuluj"/>
</div>
</asp:Panel>
</div>
<br />
</div>
<br />
<input id="def-dialog" type="button" class="btn btn-default" value="Dodaj kategorie" style="margin-left: 70%;"/><br /><br />
<div id="kategoria" style="width:100%;">
<div class="bs-example" style="width:100%;">
<asp:DataList id="cdcatalog" runat="server" DataKeyField="ID_KATEGORII" DataSourceID="SqlDataSource1" Width="98%" style="margin:auto;" CssClass="table">
<HeaderTemplate>
<th>#</th>
<th>NAZWA KATEGORII</th>
<th>LINK DO OBRAZKA</th>
<th>Edycja</th>
<th>Usuń</th>
</HeaderTemplate>
<ItemTemplate>
<td><asp:Label ID="ID_KATEGORIILabel" runat="server" Text='<%# Eval("ID_KATEGORII") %>' /></td>
<td><asp:Label ID="NAZWA_KATEGORIILabel" runat="server" Text='<%# Eval("NAZWA_KATEGORII") %>' /></td>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("IKONA") %>' /></td>
<td><asp:Label ID="Edytuj1" runat="server" ><a href="#">Edytuj</a></asp:Label></td>
<td><asp:Label ID="Usun1" runat="server" ><a href="#">Usun</a></asp:Label></td>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Baza_danych %>" SelectCommand="SELECT DISTINCT * FROM [Kategorie] WHERE ([ID_NADKATEGORII] IS NULL)">
</asp:SqlDataSource>
</div>
</div>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
</asp:Content>