Showing posts with label prerender. Show all posts
Showing posts with label prerender. Show all posts

Wednesday, March 28, 2012

Extender controls may not be registered before PreRender.

Anytime I insert a calendar extendar control or any other control from the Ajax toolkit in gridview or detailsview template. I get the page exception error. "Extender controls may not be registered before PreRender". I am using the latest Atlas DLL's.

I noticed other posts about the same subject but no clear or detailed answer to the solution. Any help will be greatly appreciated. Preferebly in vb.net please.

Hi,

by "latest Atlas DLL" do you mean ASP.NET AJAX 1.0 ?


Yes,

I meant ASP.NET AJAX 1.0 Garbin. Thanks for the offer to help. I did eventually found the fix for this problem by trial and error. I simply took the ScriptManager out of the Detailsview Control -Insertview section and placed it on the page I had the Detailsview control and Walla! problem resolved. I am sure this is probably cheating but hey it worked. If anybody has any insight as to why this happens and what is the right fix for it please enlight us all.

Once again to recreate the problem try the following steps.

1. Drag and drop a detailsview control on your page.
2. Bind the detailsview control to any datasource.
3. In Detailsview Insert mode drag and drop a textbox then any drag and drop any Atlas control ( I tried Calendar Extendar) right inside the Detailsview insert item template.
4. Bind Calendar extender to the Textbox.
5. Preview your page on your web browser and you will see the ugly exception "Extender controls may not be registered before PreRender."


Hi,

I'm not sure why it's happening, but the ScriptManager control should always be declared in the page (or in the Master Page) rather than in a control's template.


Thanks man! This fixed my problem.

I ran into this problem after I added a Login Control on my Master Page. I had to move my script manager from my "inner page" into my Master Page and that fixed the problem.

Cheers!

Saturday, March 24, 2012

Exception: Extender controls may not be registered after PreRender

Hello,

I'm dynamically adding UserControls and Extenders for those Controls to my website.
After a postback I get this exception:

"Extender controls may not be registered after PreRender."

What is the (general) problem with that?

Thanks a lot!
Heinz

I am getting the same error message trying to add a UserControl with a SliderExtender on it. This seems like it should be a common problem. I can′t find any general answers for this one, did you find a solution for it Billy_Joe?
This sounds like an issue with ASP.NET AJAX rather than something specific to the Toolkit. Have you searched the ASP.NET AJAX forums?

Hi

Im also getting the "Extender controls may not be registered before PreRender." error and was wondering if anyone found any answers. Im trying to combine a textbox and CalendarExtender together and then use it in another server control. Ive tried to use this control straight on to a page as well and it still fails. The page contains a ScriptManager and an Update panel. Im using the 1.0.10201.0 of the AjaxToolKit. Any response is appriciated.

This is my code so far:

public class CustomDateControl : Control, INamingContainer
{
private TextBox dateTextBox = new TextBox();
private CalendarExtender ajaxCalenderExtender = new CalendarExtender();

public CustomDateControl()
{
}

public string Value
{
get
{
this.EnsureChildControls();
return this.dateTextBox.Text;
}
set
{
this.EnsureChildControls();
this.dateTextBox.Text = value;
}
}

protected override void OnInit(EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager != null)
{
scriptManager.RegisterExtenderControl<CalendarExtender>(ajaxCalenderExtender, dateTextBox);
}
base.OnInit(e);
}


protected override void CreateChildControls()
{
this.dateTextBox.ID = "dateTextBox";
this.Controls.Add(dateTextBox);
this.ajaxCalenderExtender.ID = "calendarExtender";
this.ajaxCalenderExtender.TargetControlID = dateTextBox.ID;
this.ajaxCalenderExtender.Page = this.Page;
this.Controls.Add(ajaxCalenderExtender);
base.CreateChildControls();
}
}


Hi, did anyone here ever come up with an answer for this? I'm pretty stumped. I'm dynamically adding a ModelPopupExtender to my page; on the first load of the page it works fine, but on any postback it is throwing this error.

Thanks.


This problem has to do with the lifecycle of the webpart (server control) with respect to extender controls such as the ajaxcontrol toolkit.

I've once called MS support on this and was told that AJAX ControlToolkit is not supported , only AJAX.NET Extensions which means the updatepanel and scriptmanager.

It should work, i stuck a scriptmanager on a masterpage of an asp.net web site and the server control (webpart ) worked. I even used the ajax.net extensions tabcontainer and tabcontrols. Once the scriptmanager is on the page before the webpart it should work


Here's what I did to get around it:

At first, I was saving the dynamically added custom controls to a Session variable, pulling them back out as the page reloaded in order to rebuild the Control Tree. (Actually, I was saving the controls in a List<> collection, then saving that list in the session... running a foreach to pull them back out in the page_load event. To add to the complication, the custom controls was really a panel with several labels, text boxes, and AJAX extenders built into it.)

Well, a bit of research shows that controls, even custom controls, can not be re-used directly. It looks like the AJAX extenders are complaining that they had already been pre-rendered because theywere pre-rendered the last time they were put on the page, so obviously they can't be pre-rendered again. (This was a big DUH moment for me.)

So, instead of putting the controls back on the page, I wrote a quick and dirty function... It takes the old custom control as an argument and returns a brand new custom control with the same values...

private CustomPanel RefreshPanel(CustomerPanel oldPanel)
{
CustomPanel newPanel =new CustomPanel();
newPanel.value1 = oldPanel.value1;
// etc...
return newPanel;
}

// and in the Page_Load...

foreach (CustomPanel oldPanelin Session["SavedPanelsList"])
{
updatePanel.ContentTemplateContainer.Controls.Add(RefreshPanel(oldPanel));
}

Yes, it is dirty... It works for now, though, and with a deadline looming, I'm just glad that there will be time to refactor later.

I hope this helps someone get unstuck.

And, of course, the best solution remains to pre-define the controls into the form first, and set them to be visible = false by default. If you're working with 0 to 20+ of these controls, though, it might be best to do things the hard way and mess with the dynamic controls.

Wednesday, March 21, 2012

Error:Extender controls may not be registered before PreRender

I have a user control in which I use an autocomplete extender for a textbox.in code behind I register a script in OnPreRender method.I used this user control in 2 pages.In one of them it works well but in another page with the same structure I get this error "Extender controls may not be registered before PreRender".

Does anybody know what it is?

here is the user controls code:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="AddSignaturePanel.ascx.cs"Inherits="AddSignaturePanel" %>

<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Preview"Namespace="Microsoft.Web.Preview.UI.Controls"TagPrefix="asp" %>

<

asp:ButtonID="btnDivOpener"CssClass="Button"runat="server"meta:resourcekey="btnDivOpenerResource"/>

<divdir="rtl"id='PersonDiv'style=' visibility:hidden; border:1px solid #000080; position: absolute; width: 250px;background-color: #e8f1d6;'><tablewidth='100%'><tr><tdclass="TwoColTDLabelDiv"><asp:LabelCssClass="TwoColLabel"ID="lblUserName"runat="server"meta:resourcekey="lblUserNameResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxCssClass="SigPanelTextBox"ID="txtUserName"runat="server"meta:resourcekey="txtUserNameResource1"></asp:TextBox><asp:AutoCompleteExtenderID="NameAutoComplete"Visible="true"runat="server"TargetControlID="txtUserName"MinimumPrefixLength="1"ServiceMethod="GetUserByUsername"ServicePath="../../Common/Services/PersonSearchSRVC.asmx"/></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelCssClass="TwoColLabel"ID="lblSignatureKey"runat="server"meta:resourcekey="lblSignatureKeyResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxCssClass="SigPanelTextBox"ID="txtSignatureKey"runat="server"meta:resourcekey="txtSignatureKeyResource1"></asp:TextBox></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelID="lblCondition"runat="server"CssClass="TwoColLabel"meta:resourcekey="lblConditionResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxID="txtCondition"runat="server"CssClass="SigPanelTextBox"meta:resourcekey="txtConditionResource1"></asp:TextBox></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelID="lblComment"runat="server"CssClass="TwoColLabel"meta:resourcekey="lblCommentResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxID="txaComment"runat="server"CssClass="SigPanelTextBox"TextMode="MultiLine"meta:resourcekey="txaCommentResource1"></asp:TextBox></td></tr><tr><tdclass="DivButtonTDButtons"colspan="3"><asp:ButtonCssClass="Button"ID="btnSubmit"runat="server"meta:resourcekey="btnSubmitResource"/><asp:ButtonCssClass="Button"ID="btnUnSubmit"runat="server"meta:resourcekey="btnUnSubmitResource"/><asp:ButtonCssClass="Button"ID="btnCancel"runat="server"meta:resourcekey="btnCancelResource"/> </td></tr></table></div>

and in code behind I have this:

public

partialclassAddSignaturePanel :ModuleBase

{

#region

private membersprivateIEntity _entity;

#endregion

#region

Public PropertiespublicIEntity Entity

{

set

{

base.ViewState["Type"] = ((IEntity)value).Type ;base.ViewState["Key"] = ((IEntity)value).Key;

}

//get//{// return (IEntity)base.ViewState["Type&Key"];//}

}

#endregion

#region

Delegates and EventHandlerspubliceventAddSignatureEventHandler SubmitEvent;publiceventAddSignatureEventHandler UnSubmitEvent;publicvirtualvoid OnSubmit(object sender,EventArgs e)

{

string userName = txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment = txaComment.Text;try

{

User user =SecurityService.Instance.GetUser(userName);EntityReference er= Faraconesh.ApplicationFramework.Core.DataAccess.EntityReferenceDAS.Instance.GetEntityReference(base.ViewState["Key"].ToString(),base.ViewState["Type"].ToString());Signature sign =SignatureService.Instance.AddSignature(user.Person, signatureKey, er,"", comment);AddSignatureEventArgs ase =newAddSignatureEventArgs();

ase.Signature = sign;

if (sign !=null && SubmitEvent !=null)

{

SubmitEvent(

this, ase);

}

}

catch (Exception ex)

{

thrownewException(ex.Message);

}

}

publicvirtualvoid OnUnSubmit(object sender,EventArgs e)

{

string userName = txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment = txaComment.Text;User user =SecurityService.Instance.GetUser(userName);Signature sign =SignatureService.Instance.AddSignature(user.Person, signatureKey, (IEntity)user,"", comment);AddSignatureEventArgs ase =newAddSignatureEventArgs();

ase.Signature = sign;

if (sign !=null && UnSubmitEvent !=null)

{

UnSubmitEvent(

this, ase);

}

}

#endregion

#region

overridden methodsprotectedvoid Page_Load(object sender,EventArgs e)

{

btnUnSubmit.Click +=

newEventHandler(OnUnSubmit);

btnSubmit.Click +=

newEventHandler(OnSubmit);

btnDivOpener.Attributes.Add(

"onClick","openSearchDiv" +this.ClientID +"();return false;");

btnCancel.Attributes.Add(

"onClick","closeSearchDiv" +this.ClientID +"();return false;");

}

protectedoverridevoid OnPreRender(EventArgs e)

{

base.OnPreRender(e);if (!Page.ClientScript.IsClientScriptBlockRegistered("DivOpener" +this.ClientID))

{

StringBuilder strBuilder =newStringBuilder();

strBuilder.Append(

"<script type='text/javascript'>");

strBuilder.Append(

"function openSearchDiv" +this.ClientID +"(){");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.visibility='visible';");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.top= screen.availWidth/2 -250;");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.left=screen.availHeight/2;");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"}");

strBuilder.Append(

"function closeSearchDiv" +this.ClientID +"(){");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.visibility='hidden';");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"}");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"</script>");

strBuilder.Append(

Environment.NewLine);string script = strBuilder.ToString();

Page.ClientScript.RegisterClientScriptBlock(

typeof(AddSignaturePanel),"DivOpener" +this.ClientID, script);

}

if (!Page.ClientScript.IsStartupScriptRegistered("ShowModalDialog" +this.ClientID))

{

StringBuilder strBuilder =newStringBuilder();

strBuilder.Append(

"<script type='text/javascript'>");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"var PersonPopup"+this.ClientID+"= new modalDialog('PersonDiv',50,50);");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"</script>");

strBuilder.Append(

Environment.NewLine);string script=strBuilder.ToString();

Page.ClientScript.RegisterStartupScript(

typeof(AddSignaturePanel),"ShowModalDialog" +this.ClientID, script);

}

}

#endregion

publicUser GetUser()

{

string userName=txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment=txaComment.Text;User user=SecurityService.Instance.GetUser(userName);return user;

}

}

I found the solution.just in the aspx file in which I used the user control I'd overridden onprerender method but didnt call tha base prerender for it.Wink

Hi...

If u want to get ride of this error then

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

if u r using usercontrol then paste this in ur .aspx page...