Saturday, March 24, 2012

UpdatePanel + User Controls + javascript

I am have some problems executing some basic javascript from a user control within an update panel.

The UpdatePanel is as follows:

<atlas:UpdatePanel ID="DetailsPanel" Mode="Conditional" runat="server">
<ContentTemplate>
<div id="title_details" runat="server">
<asp:LinkButton ID="what"
OnClick="foo2"
Visible="false"
Font-Size="X-Small"
runat="server">
CLICK ME!
</asp:LinkButton>
</div>
</ContentTemplate>
</atlas:UpdatePanel>
The user control gets addes to the "title_details" div's controls as follows:

protected void foo(object sender, EventArgs e)
{
Control detailControl = (Control)Page.LoadControl("DetailsControl.ascx");
(detailControlas DetailsControl).upc_guid = (senderas LinkButton).CommandName;
title_details.Controls.Add(detailControl);
hideTitleBrowser();
what.Visible =true;
DetailsPanel.Update();
}

and the javascript is add as follows:

protected void Page_Load(object sender, EventArgs e) // in DetailsControl.ascx
{
using (BrowserGateway be =new BrowserGateway())
{
upc = be.getTitleByUpcGuid(1,"EN",upc_guid);
}
String scriptString ="function showTab( tab ){" +"var tabs = [\"tab1\",\"tab2\"];" +"for(i=0; i < tabs.length; i++){" +"var obj = document.getElementById(tabs[i]);" +"obj.style.display = \"none\";" +"}" +"var obj = document.getElementById(tab);" +"obj.style.display = \"block\";" +"}";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"showHidetabs", scriptString);
}


Any ideas?Hi,

1) You should use only server controls inside an UpdatePanel, otherwise you may have troubles with the associated Atlas controls.

2) Try to register your script as a startup script instead of an inline script.

Hope it helps.

No comments:

Post a Comment