Sunday, March 11, 2012

2 ScriptManager questions

1. Scripts get registers in the PagePreRenderComplete event.
2. The ScriptManager has ScriptReferences as Collection, you can use the regular method Remove, RemoveAt to unregister a script.


You can add a script at any lifecycle page using the ScriptManager.Scrip.Add method. If you want to add a script file you must use the ScriptReference object how show the code bellow.

using System;
using System.Web.UI;
namespace Email
{
public partial class _Default : Page
{

private ScriptReference sRef;

protected void Page_Load(object sender, EventArgs e)
{
sRef = new ScriptReference();
sRef.Path = "script.js";
sRef.ScriptMode = ScriptMode.Auto;
}

protected void btnAdd_Click(object sender, EventArgs e)
{
ScriptManager.Scripts.Add(sRef);
}

protected void btnRemove_Click(object sender, EventArgs e)
{
ScriptManager.Scripts.Remove(sRef);
}
}
}

How can you see, you can add and remove the script when you want.

See more.
Dynamically Assigning ASP.NET AJAX Script References


No comments:

Post a Comment