Compiler error for classes and methods?

104 views Asked by At

I'm getting an error for items such as void / sender / class etc when attempting to paste in this example of a viewstate into Visual studio. I know that the methods need to be inside a class, but even that is still bringing up an error. The code needs to be inside a script in a web control and I'm wondering what's bringing up the errors. I've tried it in a different solution / project and changing the framework, no luck.

The code is

<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="Umbraco.cms.businesslogic" %>
<%@ Import Namespace="umbraco.cms.businesslogic.web" %>
<%@ Import Namespace="umbraco.cms.businesslogic.member" %>
<%@ Import Namespace="umbraco.cms.businesslogic.propertytype" %>
<%@ Import Namespace="umbraco.cms.businesslogic.relation" %>
<%@ Import Namespace="umbraco.nodefactory" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="TemplateEngine.Docx" %>
<%@ Import Namespace="DocumentFormat.OpenXml.Packaging" %>
<%@ Import Namespace="DocumentFormat.OpenXml.Wordprocessing" %>

<script> 

public class PageStateTemplate
{
   new umbraco.cms.businesslogic.web.Document(document location);

   protected void Page_Load(object sender, EventArgs e)
   {
        if(!IsPostBack)
         {
            string str = "Welcome to Aspdotnet-Suresh Site";
         if(ViewState["SampleText"]==null)
         {
             ViewState["SampleText"] = str;
         }

         }
   }

   protected void btnClick_Click(object sender, EventArgs e)
   {
    lblString.Text = ViewState["SampleText"].ToString();
   }
}
</script>
1

There are 1 answers

1
RononDex On

You just have to create a new aspx page with the name PageStateTemplate and copy paste the whole code into the .aspx file.

That should do it