简体   繁体   中英

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. 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. In my Templates subfolder I have the following 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

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

I have tried changing <%= to <%# and calling Page.Databind() but nothing seems to work.

Any ideas on how I can accomplish this?

在ascx文件中,将GetOption1更改为GetOption1Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM