<asp:LinkButton ID="authorize" runat="server" OnClick="authorize_click">
Authorize</asp:LinkButton>
When I load the page, I get the below error,
An error occurred during the processing of . The event handler 'OnClick' is
not allowed in this page.
I don't want to have the implementation of the OnClick() method in the
script block. I prefer to keep it in the code-behind.
Please help.
From your description, you're encountering some problem adding a custom
page(with codebehind and event handlers) into SPS 2007 site, correct?
I've performed some research according to the error messages you mentioned.
It seems for the event handler and codebehind, the following configuration
section in sps virtual server's web.config file may affect it:
===========
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10"
TotalFileDependencies="50" AllowPageLevelTrace="false">
<PageParserPaths>
<PageParserPath VirtualPath="/*" CompilationMode="Always"
AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
</SafeMode>
===========
the "AllowServerSideScript="true" setting here may help eliminate the
error. here is a web article which provide a complete step for adding
custom page(that use codebehind) into SPS site:
#Adding Code-Behind to Custom Pages in SharePoint 2007
http://blogs.vertigo.com/personal/willa/Blog/Lists/Categories/Category.aspx?
Name=SharePoint%202007
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: The event handler 'OnClick' is not allowed in this page
From: =?Utf-8?B?UmF0aGluYXZlbA==?= <Rat...@community.nospam>
Subject: The event handler 'OnClick' is not allowed in this page
Date: Thu, 17 Apr 2008 08:06:02 -0700
Thanks for your advice.
The solution you have given works for a page without a master page.
In my case, the page is linked to a master page. I got other errors, when I
made changes to web.config for "PageParserPath".
I spent some more time and got a solution for this problem. Below is the
sample
code. Hope it will be useful for others.
Client Code (.aspx)
----------------------
<asp:LinkButton ID="authorize" runat="server" >Authorize</asp:LinkButton>
Codebehind (.cs)
---------------------
namespace SPLibrary
{
public class Default : Microsoft.SharePoint.WebPartPages.WebPartPage
{
protected LinkButton authorize;
protected override void OnInit(EventArgs e)
{
authorize.Click += new EventHandler(authorize_OnClick);
}
protected void authorize_OnClick(object sender, EventArgs e)
{
LinkButton authorise = FindControl("authorize") as LinkButton;
authorise.Text = "Label Changed";
// required business logic can be added.
}
}
}
So your final solution is using code behind to programmatically regsiter
the postback event handler. I agree that it's an elegant solution whch will
not require much changes. Also, thanks for sharing the result with the
community.
Have a good day!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: =?Utf-8?B?UmF0aGluYXZlbA==?= <Rat...@community.nospam>
References: <3D1F345A-B57D-4460...@microsoft.com>
<BIRTTKQo...@TK2MSFTNGHUB02.phx.gbl>
Subject: RE: The event handler 'OnClick' is not allowed in this page
Date: Fri, 18 Apr 2008 08:51:01 -0700