0

我正在尝试将 C# 变量 (myString) 引用到 HTML 中。每次我运行程序时,我都会收到以下错误:

c:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES\SPListWebPart\VisualWebPart1\VisualWebPart1UserControl.ascx(27):错误 CS0103:当前上下文中不存在名称“myString”

这是我的代码:

VisualWebPart1UserControl.ascx

  <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"   Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,   PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs"   Inherits="SPListWebPart.VisualWebPart1.VisualWebPart1UserControl" %>


<!DOCTYPE html>
<html>
<head>
<title></title>

<link rel="Stylesheet" type="text/css" href="c:\users\administrator\documents\visual studio 2010\Projects\SPListWebPart\SPListWebPart\VisualWebPart1\Stylesheet1.css" />
<ul id="sddm">


<script type ="text/javascript" src = "c:\users\administrator\documents\visual studio 2010\Projects\SPListWebPart\SPListWebPart\VisualWebPart1\JScript1.js"></script>
<script type ="text/C#" src="C:\Users\Administrator\Documents\Visual Studio  2010\Projects\SPListWebPart\SPListWebPart\VisualWebPart1\VisualWebPart1UserControl.ascx.cs"    ></script>


<li><a href="http://maindt" 
    onmouseover="mopen('m1');"
    onmouseout="mclosetime()"><%= %></a>
    <div id="m1" 
        onmouseover="mcancelclosetime()"
        onmouseout="mclosetime()">
    <a href="">Site 1</a>
    <a href="">Site 2</a>
    <a href="">Site 3</a>
    </div>
</li>

这是我的 VisualWebPart1.ascx.cs

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;


namespace SPListWebPart.VisualWebPart1
{ 
    public partial class myClass : System.Web.UI.Page
    {

        public string myString = "Hello World";

        public void Page_Load(object sender, EventArgs e)
        {


        }

    }
4

0 回答 0