繁体   English   中英

在ascx.cs中访问变量以在.ascx Webpart中使用它们

[英]Accesing variables in ascx.cs to use them in .ascx webpart

我有一个在“ Mapas.ascx.cs”中声明的变量,我想在“ Mapas.ascx”中使用它,但我不知道该怎么做。 (我正在使用sharepoint2013)

我的变量被这样声明:

    public string apiKey, direccion;

我要使用的代码是:

<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=place_id:"DIRECCIONVARIABLE"&key="APIKEYVARIABLE" allowfullscreen></iframe>

有人可以帮助我吗? 非常感谢!

如果您想要.ascx设计代码中的调用方法或属性,则应将它们定义为public static

public static string ApiKey
{
    get
    {
        return "Name";
    }
}
public static string DoSomething()
{
    //Code here
    return "What you expected";
}

然后在aspx设计代码中:

 <span><%= yourClassName.DoSomething()%> </span>
 <span><%= YourClassName.ApiKey %> </span>

更新:例如,您有以下内容:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ClassName.ascx.cs" Inherits="YourNameSpace.X.Z.ClassName" %>

在页面顶部的ascx设计代码中,因此,如果无法通过ClassName.ApiKey访问它们,则编写名称空间,例如YourNameSpace.XZClassName

也重建您的解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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