简体   繁体   English

Visual Studio 2012 中的 ViewState 语法错误?

[英]ViewState syntax error in visual studio 2012?

I get a strange error message when using viewState on a web page.在网页上使用 viewState 时收到一条奇怪的错误消息。 Using example code from Microsoft generates this error on ViewState["Text"]:使用 Microsoft 的示例代码在 ViewState["Text"] 上生成此错误:

Error 17 Cannot apply indexing with [] to an expression of type 'method group'错误 17 无法将带有 [] 的索引应用于“方法组”类型的表达式

It seems the error is not in the code, but in config or something.似乎错误不在代码中,而是在配置中。

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using OfficeOpenXml;
using vaCommonLibrary;

public partial class lista : System.Web.UI.Page
{

    public String Text
    {
        get 
        { 
            object o = ViewState["Text"]; 
            return (o == null)? String.Empty : (string)o;
        }

        set
        {
            ViewState["Text"] = value;
        }
    }

I get another error further down in my code:我在代码中进一步出现另一个错误:

ViewState["SortDirection"] = sortDirection;

gives

Error 1 Invalid token '[' in class, struct, or interface member declaration错误 1 ​​类、结构或接口成员声明中的无效标记“[”

Problem solved.问题解决了。

Your second error sounds like that code isn't in the right place您的第二个错误听起来像是该代码不在正确的位置

Absolutely correct.完全正确。 The code was right, but further down in my code there was a { missing after an IF-statement, which caused later parentheses to mismatch leading to "strange" errors.代码是正确的,但在我的代码中,在 IF 语句之后缺少一个 {,这导致后面的括号不匹配,从而导致“奇怪的”错误。 I should have seen that, but I'm kind of new to C#, and just started to migrate all my VB.NET code to C#.我应该已经看到了,但我对 C# 有点陌生,刚刚开始将我所有的 VB.NET 代码迁移到 C#。

Thanks.谢谢。

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

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