[英]How do I access public properties when sharing webforms codebehind for user control
I am trying to make an ascx control that can be templated by our front-end developers by just making a new .ascx and pointing to that specific .ascx in that instance. 我试图制作一个ascx控件,可以由我们的前端开发人员模板化,只需创建一个新的.ascx并指向该实例中的特定.ascx。 However, I am having issues with accessing properties in shared code-behind scenarios.
但是,我在共享代码隐藏方案中访问属性时遇到问题。
I have the following code behind that's shared 我分享了以下代码
public partial class TemplateCodeBehind : TemplateControlBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Ascx Available properties
public string GetOption1Value { get { return Option1; } }
public string GetOption2Value { get { return Option2; } }
public string GetOption3Value { get { return Option3; } }
public string GetOption4Value { get { return Option4; } }
}
Note that those options that are returned are public properties of the TemplateControlBase
class. 请注意,返回的那些选项是
TemplateControlBase
类的公共属性。 In my Templates subfolder I have the following ascx 在我的模板子文件夹中,我有以下ascx
<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="../TemplateCodeBehind.ascx.cs" Inherits="MyNamespace.JqueryTemplates.TemplateCodeBehind" %>
<%@ Import Namespace="MyNamespace.JqueryTemplates" %>
<div>
Option1: <%= GetOption1 %>
</div>
This compiles fine, but when I try to load my test ascx I get the following error 这编译很好,但是当我尝试加载我的测试ascx时,我收到以下错误
An error has occurred.
发生了错误。 DotNetNuke.Services.Exceptions.PageLoadException: c:\\Projects\\DNN-Dev\\Website\\DesktopModules\\Module.JqueryTemplates\\Templates\\Test.ascx(5): error CS0103: The name 'GetOption1' does not exist in the current context
DotNetNuke.Services.Exceptions.PageLoadException:c:\\ Projects \\ DNN-Dev \\ Website \\ DesktopModules \\ Module.JqueryTemplates \\ Templates \\ Test.ascx(5):error CS0103:当前上下文中不存在名称'GetOption1'
I have tried changing <%=
to <%#
and calling Page.Databind()
but nothing seems to work. 我尝试将
<%=
更改为<%#
并调用Page.Databind()
但似乎没有任何效果。
Any ideas on how I can accomplish this? 有关如何实现这一目标的任何想法?
在ascx文件中,将GetOption1
更改为GetOption1Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.