关于asp.net的增删改查问题``菜鸟求解答~~谢谢!无法取到category的值,插入为空值
(1)html页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Easyui.Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Scripts/easyUI-1.3.2/themes/default/easyui.css" rel="stylesheet" type="text/css" />
<link href="Scripts/easyUI-1.3.2/themes/icon.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/easyUI-1.3.2/jquery.easyui.min.js" type="text/javascript"></script>
<script src="Scripts/easyUI-1.3.2/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="Scripts/common.js" type="text/javascript"></script>
</head>
<body>
<div class="easyui-layout" style="width: 100%; height: 600px; text-align: center;">
<div data-options="region:'north'" style="height: 50px">
<input id="ss" />
<div id="mm" style="width: 120px; height: 120px;">
<div data-options="name:'allcategory',iconCls:'icon-ok'">
问题分类</div>
<div data-options="name:'content'">
问题内容</div>
</div>
<input type="hidden" name="reqTypes" id="txt_editType" />
<a onclick="addcategory()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">
增加问题分类</a> <a class="easyui-linkbutton" data-options="iconCls:'icon-delete'">删除问题分类</a>
<a class="easyui-linkbutton" data-options="iconCls:'icon-cut'">修改问题分类</a>
</div>
<div data-options="region:'west',split:true" title="问题分类" style="width: 200px;">
<ul id="tt"></ul>
</div>
<div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'">
</div>
</div>
<form id="addcategory" style="display: none;" action="">
<div id="dd" style="text-align: center;">
<label>
请输入问题类别</label>
<input id="txtCategoryName" name="categoryname" type="text" style="width: 150px" />
</div>
</form>
</body>
</html>
(2)js代码
function addcategory() {
$("#dd").dialog({
closable: false, //右上角的关闭按钮,因为dialog框架关联的是window框架,window框架关联的是panel框架
title: '添加问题分类', //dialog左上角的名称
modal: true, //模式化
width: 200,
height: 200,
buttons: [{ //dialog右下角的按钮,
text: '保存', //按钮名称
iconCls: 'icon-add', //按钮左侧显示的图片
handler: function () {//按钮点击之后出发的方法
alert($("#txtCategoryName").val());
// alert("category");
$("#txtCategoryName").val('');
var category = $("#txtCategoryName").val();
$.post('/ashx/UserHandler.ashx?action=add ', { category: 'category' },
function (res) {
if (res == 1) {//插入成功
$("#txtCategoryName").val('');
$("#dd").dialog("close"); //关闭该dialog
$.messager.show({//浏览器右下角弹框,
title: '提示',
msg: '恭喜您,插入数据成功!',
timeout: 5000, //弹框保留时间
showType: 'slide'//展示样式
});
}
else {//插入数据失败
$.messager.show({
title: '提示',
msg: '插入数据失败',
timeout: 5000, //弹框保留时间
showType: 'slide'//展示样式
});
}
}
)
}
}]
});
(3)一般处理程序代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Easyui.ashx
{
/// <summary>
/// UserHandler 的摘要说明
/// </summary>
public class UserHandler : IHttpHandler
{
private HttpContext context;
private DAL.SQLHelper sqlhelper = new DAL.SQLHelper();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string action = context.Request["action"];
if (string.IsNullOrEmpty(action))
{
context.Response.Write("参数错误");
return;
}
this.context = context;
switch (action.ToLower())
{
case "add":
Add();
break;
//case "delete":
// Deleted();
}
}
public int Add()
{
int res;
string category = context.Request["category"];
string sqlStr = @"insert into Category(CategoryName) values(@category)";
SqlParameter[] parameters = { new SqlParameter("@category", category) };
res = sqlhelper.ExecuteNonQuery(sqlStr, parameters, CommandType.Text);
return res;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}其中category一直取到为空值~~~希望知道!!调试时候看到res也是1 ,为何插入的为空值!!菜鸟求指导!!感谢@@@@
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4809/viewspace-3150327/ ,如需转载,请注明出处,否则将追究法律责任。