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.vb1Imports 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!
No comments:
Post a Comment