Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script registration labyrinth – startup scripts and $find (asynchronous postback)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AsynchronousPostback.aspx.cs" Inherits="ScriptRegistrationLabyrinth.AsynchronousPostback" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<asp:Timer runat="server" ID="BretonTimer" OnTick="BretonTimer_Tick" Interval="2000" />
<asp:Label runat="server" ID="Label1" /><br />
<asp:Button runat="server" ID="StopBretonButton" Text="Stop!" OnClick="StopBretonButton_Click" />
<asp:Button runat="server" ID="JustAnotherPostbackButton" Text="Just another postback" />
<asp:AsyncPostBackTrigger ControlID="BretonTimer" />
<asp:AsyncPostBackTrigger ControlID="StopBretonButton" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ScriptRegistrationLabyrinth
public partial class AsynchronousPostback : System.Web.UI.Page
protected void BretonTimer_Tick(object sender, EventArgs e)
Label1.Text += "*";
protected void StopBretonButton_Click(object sender, EventArgs e)
string script = string.Format(
"(function() {{" +
"var fn = function() {{" +
"$find(\"{0}\")._stopTimer();" +
"Sys.Application.remove_load(fn);" +
"}};" +
"Sys.Application.add_load(fn);" +
"}})();", BretonTimer.ClientID);
ScriptManager.RegisterStartupScript(this, this.GetType(), "key1", script, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.