Wednesday, March 28, 2012

Page.ClientScript.RegisterStartupScript in updatepanel problem with Beta1.0 ??

Open a new window fails!!! (but with CTP OK!)

protected override void OnClick(EventArgs e)
{
if (grid != null && grid.DataKeyNames.Length > 0)
{
int[] selected = grid.GetSelectedIndexes();
if (selected.Length > 0)
{
grid.SelectedIndex = selected[0];
DataKey dataKey = grid.SelectedDataKey;
if (dataKey != null)
{
string separator1;
if (DialogNavigateUrl.ToString().IndexOf("?") != -1)
{
separator1 = "&";
}
else
{
separator1 = "?";
}
StringBuilder sb = new StringBuilder();
string separator2 = string.Empty;
IDictionaryEnumerator enumerator = dataKey.Values.GetEnumerator();
while (enumerator.MoveNext())
{
sb.Append(separator2);
sb.Append(enumerator.Key);
sb.Append("=");
sb.Append(enumerator.Value);
separator2 = "&";
}
string format;
format = "window.open('{0}{5}{6}{7}Parent={4}',null,'height={1},width={2},status=1,toolbar=0,menubar=0,location={3},resizable=1,scrollbars=1');";
string script =
String.Format(CultureInfo.CurrentCulture, format, DialogNavigateUrl.ToString().Replace("~/", ""), DialogHeight.Value, DialogWidth.Value,
Convert.ToByte(DialogLocation), this.ClientID, separator1, sb.ToString(), separator2);
Type type = this.GetType();
if (!Page.ClientScript.IsStartupScriptRegistered("clientScript"))
{
Page.ClientScript.RegisterStartupScript(type, "clientScript", script, true);
}
}
}
}
base.OnClick(e);
}

For the control to work inside an UpdatePanel you need to call the new static registration APIs on the ScriptManager class. They have basically the same parameters as the Page.ClientScript methods but the new first parameter is the control doing the registration (usually "this").

Thanks,

Eilon


More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon

No comments:

Post a Comment