当前位置 : 主页 > 网络编程 > ASP >

ASP.net代码背后和来自C#

来源:互联网 收集:自由互联 发布时间:2021-06-24
我有一个简单的页面如下: Default.aspx的 %@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %htmlbodyform method="POST" action="Default.aspx"Enter Number: input type="text" name="cNum" va
我有一个简单的页面如下:

Default.aspx的

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<html>
<body>

<form method="POST" action="Default.aspx">

Enter Number: <input type="text" name="cNum" value="7707744436276244" /><br />
<input type="submit" value="Submit" />
</form>


</body>
</html>

和Default.aspx.cs背后的代码

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    public string ServerSideVariable;


    protected void Page_Load(object sender, EventArgs e)
    {
       string n = String.Format("{0}", Request.Form['cNum']); ERROR Here<--- too many character in character literall....

        string pval = "Passed value";
        ServerSideVariable = pval;

    }
}

为什么会发生错误?

另外我打算在代码后面实现与DB建立连接并将响应返回给ASP.net,任何人都知道这是怎么做到的?

在C#中,’是为字符文字保留的.
“是为字符串文字保留的.

char char1 = 'Z';        // Character literal
string string1 = "ZZZ";  // String literal

C#参考文献:

> Character literals
> String literals
> [] Operator

请尝试以下方法:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    public string ServerSideVariable;


    protected void Page_Load(object sender, EventArgs e)
    {
       string n = String.Format("{0}", Request.Form["cNum"]); //ERROR Here<--- too many character in character literall....

        string pval = "Passed value";
        ServerSideVariable = pval;

    }
}

关于第2个问题,请阅读http://www.oracle.com/technetwork/issue-archive/2011/11-sep/o51odt-453447.html.

网友评论