Showing posts with label registered. Show all posts
Showing posts with label registered. 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!

Extended controls may not be registered before Pre-Render

hi all,

i get the following error message when trying to load a usercontrol containing a modalpopupextender:
"extended controls may not be registered before pre-render"

no line specified, no more info about what's wrong, and almost everything is done with click 'n' drag in design mode (vwd 2005).

default.aspx and its codebehind:http://www.aspsidan.se/code/default.asp?c=9359

editcontent.ascx and its codebehind:http://www.aspsidan.se/code/default.asp?c=9361

the error message:http://www.aspsidan.se/code/default.asp?c=9360

editcontent.ascx is, as you can see, within a loginview, and it's not until i log on that i get the problem. i guess this error has something to do with the page life cycle, but i have no clue of how to get around it...

(i posted the code already in another forum, so i refer to those pages. i hope they're available even if you're not logged on. i've tried when i was offline and it worked, so it shouldn't be a problem...)

Hi lycken,

It is a common issue. You should add base.OnPreRender at the beginning ofvoid OnPreRender(EventArgs e){};

For more , pleaseread this. If it doesn't work, please feel free to let me know.

Best regards,

Jonathan


hi jonathan,

thanks a lot for the reply! it really does save my day that there is a solution to this.

however, neither your answer nor the article you linked me to helped me all the way. i understand i have to call the base.OnPreRender routine, but i can't figure out where in my code to put the call. i am coding in vb, so if you could explain it with vb examples instead of c# it would help me ;)

thanks again for your help!

-tomas


Hi Lycken,

Would you please give us a tiny and workable repro? So you can benefit from it directly. Thanks for your understanding.

Best regards,

Jonathan


hi again jonathan,

i provided all my source code in the first post - unless the links are not working. it's pasted below anyway - excuse the lenghtyness... and again - thanks for helping out!

the db is designed as follows:

Texts
******
TextID | int (identifier, primary key)
TextName | varchar(15)
Text | varchar(max)

Default.aspx

1<%@. Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb"Inherits="_Default" title="Untitled Page" Theme="SMK" Trace="true" %>
2<%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
3<%@. Register TagPrefix="list" TagName="Concerts" src="~/konsertprogram/Concerts.ascx" %>
4<%@. Register TagPrefix="ucl" TagName="EditContent" src="~/admin/EditContent.ascx" %>
5
6<asp:Content ID="Content1" ContentPlaceHolderID="Left" Runat="Server">
7 <asp:Image ID="LeftPaneImage" runat="server" ImageUrl="~/image/bredvid_konserter.jpg" />
8</asp:Content>
9<asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server">
10 <asp:Label ID="TextLabel" runat="server" />
11 <div style="text-align:right; width:100%;">
12 <asp:LoginView ID="LoginView1" runat="server">
13 <RoleGroups>
14 <asp:RoleGroup Roles="Admin">
15 <ContentTemplate>
16 <ucl:EditContent ID="EditContentUserControl" runat="server" TextToEdit="hem" />
17 </ContentTemplate>
18 </asp:RoleGroup>
19 </RoleGroups>
20 </asp:LoginView>
21 </div>
22
23 <div class="row">
24 <div style="float:left;">
25 <h1>N?sta konsert:</h1>
26 <list:Concerts ID="Concerts" runat="server" ItemsToShow="1" />
27 </div>
28
29 <div style="float:left;">
30 <h1>En till ruta</h1>
31 <p>med lite info</p>
32 </div>
33 </div>
34
35</asp:Content>

Default.aspx.vb

1Imports System.Configuration
2Imports System.Data.SqlClient
3Imports System.Data.SqlDbType
4Imports ErrorHandling
5
6PartialClass _Default
7Inherits System.Web.UI.Page
8
9Dim objConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("SMK").ConnectionString)
10
11Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load
12Dim objCmdAs New SqlCommand("SELECT [Text] FROM [Texts] WHERE [TextName] ='hem'", objConn)
13
14Try
15 objConn.Open()
16 TextLabel.Text = StringFunctions.FormatText(objCmd.ExecuteScalar)
17Catch exAs Exception
18 Err.Log(ex)
19Finally
20 If objConn IsNotNothing Then objConn.Close()
21End Try
22 End Sub
23End Class

EditContent.ascx

1<%@. Control Language="VB" AutoEventWireup="false" CodeFile="EditContent.ascx.vb"Inherits="admin_EditContent" %>
2<%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
3<asp:ScriptManager ID="ScriptManager1" runat="server">
4</asp:ScriptManager>
5<asp:LinkButton ID="EditText" runat="server" CssClass="textr">Redigera texten</asp:LinkButton>
6<asp:Panel ID="ModalPanel" runat="server" CssClass="modalpu">
7 <asp:Button ID="btnBold" runat="server" Font-Bold="True" Text="F" Width="30px" />
8 <asp:Button ID="btnItalic" runat="server" Font-Italic="True" Text="K" Width="30px" />
9 <asp:Button ID="btnUnderline" runat="server" Font-Underline="True" Text="U" Width="30px" />
10 <asp:Button ID="btnHeader" runat="server" Text="Rubrik" Width="80px" />
11 <asp:Button ID="btnText" runat="server" Text="Text" Width="80px" /><br />
12 <asp:TextBox ID="tbContent" runat="server" Height="400px" Width="430px" TextMode="MultiLine" /><br />
13 <asp:Button ID="OKButton" runat="server" Font-Bold="True" Text="Skicka" Width="90px" />
14 <asp:Button ID="CancelButton" runat="server" Text="Avbryt" Width="90px" /><br />
15 <asp:Label ID="lblStatus" runat="server" />
16</asp:Panel>
17<cc1:ModalPopupExtender ID="ModalPopupExtender" runat="server"
18 TargetControlID="EditText"
19 PopupControlID="ModalPanel"
20 x="0"
21 Y="0"
22 DropShadow="true"
23 RepositionMode="none"
24 OkControlID="OKButton"
25 OnOkScript="__doPostBack('ctl00$Content$LoginView1$EditContentUserControl$OKButton','')"
26 CancelControlID="CancelButton"
27 BackgroundCssClass="modalbg" />
EditContent.ascx.vb
1Imports System.Configuration
2Imports System.Data.SqlClient
3Imports System.Data.SqlDbType
4Imports ErrorHandling
5
6PartialClass admin_EditContent
7Inherits System.Web.UI.UserControl
8
9Dim objConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("SMK").ConnectionString)
10Private _textToEditAs String
11
12 Public WriteOnly Property TextToEdit()As String
13 Set(ByVal valueAs String)
14 _textToEdit = value
15End Set
16 End Property
17
18 Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load
19Dim objCmdAs New SqlCommand("SELECT [Text] FROM [Texts] WHERE [TextName] = @.TextName", objConn)
20
21Dim objParamAs New SqlParameter("@.TextName", VarChar)
22 objParam.Value = _textToEdit
23 objCmd.Parameters.Add(objParam)
24
25Try
26 objConn.Open()
27 tbContent.Text = objCmd.ExecuteScalar
28Catch exAs Exception
29 Err.Log(ex)
30Finally
31 If objConn IsNotNothing Then objConn.Close()
32End Try
33 End Sub
34
35 Protected Sub OKButton_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles OKButton.Click
36Dim objCmdAs New SqlCommand("UPDATE Texts SET [Text] = @.Text WHERE [TextName] = @.TextName", objConn)
37
38Dim objParamAs New SqlParameter("@.Text", VarChar)
39 objParam.Value = tbContent.Text
40 objCmd.Parameters.Add(objParam)
41
42 objParam =New SqlParameter("@.TextName", VarChar)
43 objParam.Value = _textToEdit
44 objCmd.Parameters.Add(objParam)
45
46Try
47 objConn.Open()
48 objCmd.ExecuteNonQuery()
49 lblStatus.Text ="Uppdaterat!"
50Catch exAs Exception
51 Err.Log(ex)
52Finally
53 If objConn IsNotNothing Then objConn.Close()
54End Try
55
56 objConn =Nothing
57 objCmd =Nothing
58 End Sub
59End Class



Hi Luken,

Would you please add this code to EditContent.ascx.vb?

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...
}

I have copied your code to my project and did some modifications(comment and rename work only) , it works well on my machine. Also where's your master page? If it doesn't work, would you please create aworkable sample and give us the links so that we can download your project. Thanks

Best regards,

Jonathan


i'd love to add it to editcontent.ascx.vb, but i don't know how to re-write it to vb. i get syntax errors on "base" when i try. what is it called with vb syntax?


Hi Lycken,

For example,

C# code

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...
}

Convert to VB Code,

Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs) ' add base.OnPreRender(e); at the beginning of the method. MyBase.OnPreRender(e) ' codes to handle with your controls.

End Sub

Here is anuseful tool.

I hope this help.

Best regards,

Jonathan


thanks a lot! it's working fine now - or at least this part of the solution is... i have a couple of other things that aren't doing so well at the moment, but i'll work on those for yet a while before i post here.

again, thanks!

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...