如何实现web页面的提示保存功能

时间:2009-03-15 02:52:39
【文件属性】:

文件名称:如何实现web页面的提示保存功能

文件大小:8KB

文件格式:TXT

更新时间:2009-03-15 02:52:39

ASP.Net 控件 源码 资源

每每听到客户抱怨自己修改和很久的数据由于自己的一个误操作而丢失时,总想让web页面也有像window窗体一样具有提示保存的功能。所以,经过一段时间的研究以后终于实现了这个功能!============ checksave.js =============================== test.aspx ===============<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" Inherits="Test.test" smartNavigation="True" %> test

sohu
yahoo
MTR LinkButton
======== test.aspx.vb ===============Public Class test Inherits System.Web.UI.Page Protected WithEvents txtSave As System.Web.UI.WebControls.TextBox Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents txtCheckFlag As System.Web.UI.WebControls.TextBox#Region " Web Form Designer Generated Code " ‘This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init ‘CODEGEN: This method call is required by the Web Form Designer ‘Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ‘Put user code to initialize the page here txtSave.Style.Item("display") = "none" txtCheckFlag.Style.Item("display") = "none" LinkButton1.Attributes("onclick") = "javascript:return checksave(this.href)" ‘ Page.RegisterStartupScript("Prompt", "") End Sub Private Sub txtCheckFlag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCheckFlag.TextChanged Session("URL") = txtCheckFlag.Text If checkdata() Then ‘Session("Data") = Me.Data If InStr(txtCheckFlag.Text, "__doPostBack") > 0 Then Page.RegisterStartupScript("warning", "") Else Page.RegisterStartupScript("warning", "") End If Else If InStr(txtCheckFlag.Text, "__doPostBack") > 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("warning", "") Else If InStr(txtCheckFlag.Text, "javascript:") > 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("Redirect", "") Else Page.RegisterStartupScript("Redirect", "") Response.End() End If End If End If End Sub Private Sub txtSave_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSave.TextChanged If savedata() = False Then txtSave.Text = "" txtCheckFlag.Text = "" Exit Sub End If Me.ViewState("flag") = True If InStr(txtCheckFlag.Text, "__doPostBack") > 0 Then Page.RegisterStartupScript("TxtSave", "") Else If InStr(txtCheckFlag.Text, "javascript:") > 0 Then Session("URL") = Replace(txtCheckFlag.Text, "javascript:", "") Page.RegisterStartupScript("TxtSave", "") Else Page.RegisterStartupScript("Redirect", "") ‘Response.Redirect(Session("URL")) ‘Response.End() End If End If txtSave.Text = "" txtCheckFlag.Text = "" End Sub Private Function checkdata() As Boolean ‘check whether user really had modified the data Return True End Function Private Function savedata() As Boolean ‘do save data here! Return True End Function Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click If Me.ViewState("flag") = True Then Page.RegisterStartupScript("Redict", "") Else Page.RegisterStartupScript("Redict", "") End If End SubEnd Class


网友评论

  • 不错的资源,挺好的
  • 很好的资源,请试试