简体   繁体   English

在共享webforms代码隐藏以进行用户控制时,如何访问公共属性

[英]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.

相关问题 如何从代码隐藏访问用户控件的公共属性? - How do I access a public property of a User Control from codebehind? 如何访问代码隐藏 object 中的公共变量以进行 ascx 控件? (内联表达式) - How do I access a public variable in the codebehind object for an ascx control? (Inline Expression) 如何从代码隐藏中在用户控件的内容控件中的数据模板中启动故事板? - How do I start a Storyboard in a Data Template in a Content Control in a User Control from codebehind? 如何通过用户控件标记访问母版页属性? - How do I get access to master page properties via user control markup? 无法从通用处理程序访问用户控件的公共属性 - Unable to access user control public properties from generic handler 如果我以编程方式加载它,如何访问用户控件属性? - How to access user control properties if i load it programatically? 如何引用 HTML 的输入<textarea>控制代码隐藏? - How do I reference the input of an HTML <textarea> control in codebehind? 如何阻止Designer在用户控件上生成公共属性的代码? - How do you stop the Designer generating code for public properties on a User Control? 如何访问控件类型变量的可能属性? - How do I access a Control type variable's possible properties? 如何访问用户控件中的特定控件? - How do I access a particular control within a user control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM