Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script registration labyrinth – startup scripts and $find (alternative)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Alternative.aspx.cs" Inherits="ScriptRegistrationLabyrinth.Alternative" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager runat="server" ID="ScriptManager1">
</telerik:RadScriptManager>
<telerik:RadAjaxManager runat="server" ID="AjaxManager1">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="AjaxPanel">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="AjaxPanel" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<asp:Timer runat="server" ID="Control1" Enabled="false" />
<asp:Panel runat="server" ID="AjaxPanel">
<asp:Button runat="server" ID="Button1" OnClick="ResponseScriptsButton_Click" Text="ResponseScripts - AJAX" />
<asp:Button runat="server" ID="Button3" OnClick="AddInit_Click" Text="add_init - AJAX" />
</asp:Panel>
<asp:Panel runat="server" ID="NonAjaxPanel">
<asp:Button runat="server" ID="Button2" OnClick="ResponseScriptsButton_Click" Text="ResponseScripts - Non AJAX" />
<asp:Button runat="server" ID="Button4" OnClick="AddInit_Click" Text="add_init - Non AJAX" />
</asp:Panel>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace ScriptRegistrationLabyrinth
{
public partial class Alternative : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ResponseScriptsButton_Click(object sender, EventArgs e)
{
string script = string.Format("alert($find('{0}'));", Control1.ClientID);
AjaxManager1.ResponseScripts.Add(script);
}
protected void AddInit_Click(object sender, EventArgs e)
{
string script = string.Format("Sys.Application.add_init(function() {{ setTimeout(function() {{ alert($find('{0}')); }}, 0); }});", Control1.ClientID);
RadScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "add_init", script, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment