Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.net代码在C中的后台和后台#_C#_Asp.net - Fatal编程技术网

C# ASP.net代码在C中的后台和后台#

C# ASP.net代码在C中的后台和后台#,c#,asp.net,C#,Asp.net,我在下面有一个简单的页面: 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="c

我在下面有一个简单的页面:

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;

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
公共部分类\u默认值:System.Web.UI.Page
{
公共字符串ServerSideVariable;
受保护的无效页面加载(对象发送方、事件参数e)
{

string n=string.Format(“{0}”,Request.Form['cNum']);此处错误在
'
标记内不能有多个字符。您的代码应为:

string n = String.Format("{0}", Request.Form["cNum"]); // Double quotes here
至于你的第二个问题,这是一个非常广泛的问题,涵盖了很多db主题/可能性。你应该缩小你的问题范围,提出一些与此相关的具体问题。

改变

string n = String.Format("{0}", Request.Form['cNum']); 


您需要双引号(
)来表示字符串文字。

使用双引号。单引号用于一个字符

Request.Form["cNum"]
char char1 = 'Z';        // Character literal
string string1 = "ZZZ";  // String literal
在C#中,
是为字符文字保留的。
是为字符串文本保留的

char char1 = 'Z';        // Character literal
string string1 = "ZZZ";  // String literal
C#参考文献:

请尝试以下操作:

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;

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
公共部分类\u默认值:System.Web.UI.Page
{
公共字符串ServerSideVariable;
受保护的无效页面加载(对象发送方、事件参数e)
{

string n=string.Format(“{0}”,Request.Form[“cNum”]);//此处出错我认为发生错误是因为Request.From有许多参数

要获得Post参数,更好的方法是:

NameValueCollection nameValueCollection = Request.Form;

string cnum = nameValueCollection["cNum"];

虽然我还没有测试过,但我认为这会很好。

有人知道如何将值从C#(代码隐藏)传递回ASP.net(或向上)吗?它只是简单地引用ASP.net中的变量吗?还是顶部的XML文件需要拉取它?ADO.net不做oracle PL/SQL+1:解释为什么必须使用双引号而不是单引号。