防止客户再三提交的2种减轻方案,生命周期DEMO

可在服务器端加载方法:

<%@ Page Language=”C#” %>
<!DOCTYPE Html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
 “;
<html XMLns=”” >
<head runat=”server”>
    <title>Client Event Example</title>
    <style type=”text/Css”>
    #OuterPanel { width: 600px; height: 200px; border: 2px solid blue;
}
    #NestedPanel { width: 596px; height: 60px; border: 2px solid
green;
                   margin-left:5 px; margin-right:5px;
margin-bottom:5px;}
    </style>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        <asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
        <Scripts>
           <asp:ScriptReference Path=”ClientEventTest.js” />
        </Scripts>
        </asp:ScriptManager>
        <asp:UpdatePanel ID=”OuterPanel” UpdateMode=”Conditional”
runat=”server”>
        <ContentTemplate>
            Postbacks from inside the outer panel and inner panel are
            asynchronous postbacks. PRM =
Sys.WebForms.PageRequestManager. APP = Sys.Application.

复制代码 代码如下:

            <br /><br />
            <asp:Button ID=”OPButton1″ Text=”Outer Panel Button”
runat=”server” />
防止客户再三提交的2种减轻方案,生命周期DEMO。            Last updated on
            <%= DateTime.Now.ToString() %>
            <br /><br />

private void OnLoading()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(” function pageLoad(){var manager =
Sys.WebForms.PageRequestManager.getInstance(); “);
sb.Append(” manager.add_beginRequest(OnBeginRequest);
manager.add_endRequest(OnEndRequest)} var lcPostbackElementID;”);
sb.Append(” function OnBeginRequest(sender, args){ lcPostbackElementID =
args.get_postBackElement().id.toLowerCase(); if (lcPostbackElementID
=== \”btnadwords\”){$get(\”btnAdWords\”).disabled = true;
$get(\”btnAdWords\”).value=’正在提交…’;}} “);
sb.Append(” function OnEndRequest(sender, args){if (lcPostbackElementID
=== \”btnadwords\”){ $get(\”btnAdWords\”).disabled = false;
$get(\”btnAdWords\”).value=’确定’;}} “);

            <asp:UpdatePanel ID=”NestedPanel”
UpdateMode=”Conditional” runat=”server”>
            <ContentTemplate>
                <asp:Button ID=”NPButton1″ Text=”Nested Panel 1
Button” runat=”server” />

ScriptManager.RegisterStartupScript(Page, Page.GetType(), “btnAdWords”,
sb.ToString(), true);
}

                Last updated on
                <%= DateTime.Now.ToString() %>
                <br />
            </ContentTemplate>
            </asp:UpdatePanel>
        </ContentTemplate>
        </asp:UpdatePanel>

也可平昔写在页面脚本里:

        <input type=”button” onclick=”Clear();” value=”Clear” />

复制代码 代码如下:

        <asp:Button ID=”FullPostBack” runat=”server” Text=”Full
Postback” />
        <a href=” Window
Unload</a>
        <br />
        <span id=”ClientEvents”></span>   
    </div>
<script type=”text/javascript”>
// Hook up Application event handlers.
var app = Sys.Application;
app.add_load(ApplicationLoad);
app.add_init(ApplicationInit);
app.add_disposing(ApplicationDisposing);
app.add_unload(ApplicationUnload);

<script>
function pageLoad()
{
var manager = Sys.WebForms.PageRequestManager.getInstance();
manager.add_beginRequest(OnBeginRequest);
manager.add_endRequest(OnEndRequest)
}
var lcPostbackElementID;
function OnBeginRequest(sender, args)
{
lcPostbackElementID = args.get_postBackElement().id.toLowerCase();
if (lcPostbackElementID === ‘btnadwords’)
{
$get(‘btnAdWords’).disabled = true;
$get(‘btnAdWords’).value=’正在提交…’;
}
}
function OnEndRequest(sender, args)
{
if (lcPostbackElementID === \”btnadwords\威尼斯赌场,”)
{
$get(‘btnAdWords’).disabled = false;
$get(‘btnAdWords’).value=’确定’;
}
}
< /script>

// Application event handlers for component developers.
function ApplicationInit(sender) {
  var prm = Sys.WebForms.PageRequestManager.getInstance();
  if (!prm.get_isInAsyncPostBack())
  {
      prm.add_initializeRequest(InitializeRequest);
      prm.add_beginRequest(BeginRequest);
      prm.add_pageLoading(PageLoading);
      prm.add_pageLoaded(PageLoaded);
      prm.add_endRequest(EndRequest);
  }
  $get(‘ClientEvents’).innerHTML += “APP:: Application init.
<br/>”;
}
function ApplicationLoad(sender, args) {
  $get(‘ClientEvents’).innerHTML += “APP:: Application load. “;
  $get(‘ClientEvents’).innerHTML += “(isPartialLoad = ” +
args.get_isPartialLoad() + “)<br/>”;
}
function ApplicationUnload(sender) {
  alert(‘APP:: Application unload.’);
}
function ApplicationDisposing(sender) {
  $get(‘ClientEvents’).innerHTML += “APP:: Application disposing.
<br/>”;
 
}
// Application event handlers for page developers.
function pageLoad() {
  $get(‘ClientEvents’).innerHTML += “PAGE:: Load.<br/>”;
}

越来越多内容请参见:

function pageUnload() {
  alert(‘Page:: Page unload.’);
}

复制代码 代码如下: private
void OnLoading() { System.Text.StringBuilder sb = new
System.Text.StringBuilder(); sb.Append(” function pageLoa…

// PageRequestManager event handlers.
function InitializeRequest(sender, args) {
  $get(‘ClientEvents’).innerHTML += “<hr/>”;
  $get(‘ClientEvents’).innerHTML += “PRM:: Initializing async
request.<br/>”; 
}
function BeginRequest(sender, args) {
  $get(‘ClientEvents’).innerHTML += “PRM:: Begin processing async
request.<br/>”;
}
function PageLoading(sender, args) {
  $get(‘ClientEvents’).innerHTML += “PRM:: Loading results of async
request.<br/>”;
  var updatedPanels = printArray(“PanelsUpdating”,
args.get_panelsUpdating());
  var deletedPanels = printArray(“PanelsDeleting”,
args.get_panelsDeleting());
 
  var message = “–>” + updatedPanels + “<br/>–>” +
deletedPanels + “<br/>”;
 
  document.getElementById(“ClientEvents”).innerHTML += message;
}
function PageLoaded(sender, args) {
  $get(‘ClientEvents’).innerHTML += “PRM:: Finished loading results of
async request.<br/>”;
  var updatedPanels = printArray(“PanelsUpdated”,
args.get_panelsUpdated());
  var createdPanels = printArray(“PaneslCreated”,
args.get_panelsCreated());
   
  var message = “–>” + updatedPanels + “<br/>–>” +
createdPanels + “<br/>”;
       
  document.getElementById(“ClientEvents”).innerHTML += message;
}
function EndRequest(sender, args) {
  $get(‘ClientEvents’).innerHTML += “PRM:: End of async
request.<br/>”;
}

// Helper functions.
function Clear()
{
  $get(‘ClientEvents’).innerHTML = “”;
}
function printArray(name, arr)
{
    var panels = name + ‘=’ + arr.length;
    if(arr.length > 0)
    {
        panels += “(“;
        for(var i = 0; i < arr.length; i++)
        {
            panels += arr[i].id + ‘,’;
        }
        panels = panels.substring(0, panels.length – 1);
        panels += “)”;
    }
    return panels;
}
</script>
    </form>
</body>
</html>

admin

网站地图xml地图