Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Ich möchte beim Verlassen einer ASP Seite den Inhalt speichern.

Bevor jetzt hier einwände kommen ich weiß das das nicht einfach so möglich ist, aber ich suche (unkonventionelle) Ideen ;)

Ich hab dazu mal eine kleine Testseite erstellt:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SaveOnClose.aspx.cs" Inherits="ModalPopupSample.SaveOnClose" %>

<!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>Untitled Page</title>

<script type="text/javascript">

onbeforeunload = function AskSave()
{
if (confirm('Wollen Sie vor dem Beenden Ihre Änderungen speichern?') == true)
{
__doPostBack('btnSave','');
alert('Daten gespeichert');
}
}


</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
</asp:ScriptManager>

<asp:Label ID="Label1" runat="server" Text="Wert1:"></asp:Label><asp:TextBox ID="txt1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Wert2:"></asp:Label><asp:TextBox ID="txt2" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="Wert3:"></asp:Label><asp:TextBox ID="txt3" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSave" runat="server" Text="Speichern" OnClick="btnSave_Click" />
<asp:HiddenField ID="Saved" runat="server" />

</div>
</form>
</body>
</html>
[/PHP]

[PHP]
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Services;

namespace ModalPopupSample
{
public partial class SaveOnClose : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
File.Delete("c:\\savetest.txt");
}

protected void btnSave_Click(object sender, EventArgs e)
{
FileStream file = new FileStream("c:\\savetest.txt", FileMode.CreateNew);
StreamWriter w = new StreamWriter(file);
w.WriteLine(txt1.Text);
w.WriteLine(txt2.Text);
w.WriteLine(txt3.Text);
w.Close();
file.Close();
}
}
}

Die Sache hier ist die das das alert('Daten gespeichert') dafür sorgt das der Webserver genug Zeit hat den Postback durchzuführen und die Daten zu speichern.

Ich find das allerdings nicht so schön jedesmal noch eine Messagebox zu bringen, außerdem könnte es evtl. zu Problemen führen wenn der Server mal nen Hänger hat und die Message Box zu schnell geschlossen wird.

Ich hab auch mal probiert einen Webservice zu schreiben der solange wartet bis gespeichert wurde und im Javascript beim Beenden so lange zu warten bis dieser Webservice zurück gekommen ist, aber das hat leider nicht geklappt.

Ich denke zwar nicht das sich hier eine 100%tige Lösung finden lässt, aber ich lasse mich gerne überraschen ;)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.