注册 登录
编程论坛 ASP技术论坛

求助:asp.net不能显示

lbj163 发布于 2012-07-26 10:48, 342 次点击
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"  %>
<html>
<head>
</head>
<body>
<form method="post" id="form1" action="" runat="server">
    <input type="text" name="name" runat="server">
<input type="submit" value="提交" runat="server"  onclick="Clicka" >
</form>
</body>
</html>
WebForm1.aspx.cs  页面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


namespace WebApplication3
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Clicka(object sender, EventArgs e)
        {
             int name1 = Convert.ToInt32(Request.Form["name"]);
             Response.Write("name1");
         

        }
    }


页面显示不出input提交的值      请大家给看看  是哪出问题了!  谢谢
1 回复
#2
xmlz2012-07-26 21:57
1、onclick在客户端运行,应该写客户端代码。服务器端应该是onServerClick
2、 action没有指定接收参数的页面,Request应该在接收页面使用
3、如果是当前页面获取参数,直接用客户端脚本就可以了,不需要写后台。
4、按照你的意图Response.Write("name1")应为Response.Write(name1);

VS2005代码test.aspx,当然这么写没什么意义
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.

<html xmlns="http://www. >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
<form method="post" id="form1" action="test.aspx" runat="server">
    <input id="Text1" type="text" name="text1" runat="server">
<input id="Submit1" type="submit" value="提交" runat="server">
</form>
</body>
</html>

test.aspx.cs代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.Form["text1"]);
    }
}

[ 本帖最后由 xmlz 于 2012-7-27 09:52 编辑 ]
1