表单请求

本文介绍了一个基于ASP.NET的产品分类修改功能实现细节,包括表单验证、错误处理及页面跳转等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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;
using System.IO;


public partial class productSortModify : System.Web.UI.Page
{
    public ArrayList errorStrList = new ArrayList(20);
    public string[] errorStr;
    public ArrayList errorObjList = new ArrayList();    
    public int i = 0;
    public sortTitle.productSort st = new sortTitle.productSort();
    public string Stitle = "";
    public long Psid;        //地址栏参数    
    public string act = "";
   
    public long Rc;
    public string[] Pic = new string[1];
    public List<Model.productSort> l_level;


    struct errorData
    {
        public int errorI;
        public string errorObj;
    }


    protected void Page_Load(object sender, EventArgs errorStrct)
    {
        Bll.Cookie.checkSession();        
        Model.Pages p;
        Model.productSort m;
        #region ==接收地址栏==
         Psid = Common.Functions.ConvertInt64(Request.QueryString["id"], 0);
        #endregion


        #region ==赋初值==
            m = new Model.productSort();
            m.d_Psid = Psid;
            m = Bll.productSort.Select_Detail(m);
            Stitle = m.Stitle;                              
        #endregion


        errorStr = new string[0];


        #region ==处理表单提交==
        act = Request.Form["act"];
        if (act == "modify")
        {
            #region==接收表单==
            Stitle = Common.Functions.convers(Request.Form["Stitle"].ToString().Trim());                      
            #endregion


            #region ==验证表单==
            i = 0;
            if (string.IsNullOrEmpty(Stitle))
            {
                errorData errorStruct = new errorData();
                errorStruct.errorI = 1;
                errorStruct.errorObj = "Stitle";
                errorObjList.Add(errorStruct);
                errorStrList.Add("产品分类不能为空");
                i++;
            }else if (Common.Functions.strLength(Stitle) > 100)
            {
                errorData errorStruct = new errorData();
                errorStruct.errorI = 1;
                errorStruct.errorObj = "Stitle";
                errorObjList.Add(errorStruct);
                errorStrList.Add("产品分类不能多于50个汉字(100个字符),现在是" + Common.Functions.strLength(Stitle) + "个字符");
                i++;
            }
            else
            {
                Model.productSort m2 = new Model.productSort();
                m2.s_Keywords = Stitle;
          
                p = new Model.Pages();               
                l_level = Bll.productSort.Select_List(m2, ref p, ref Rc);
                if (l_level.Count> 0)
                {
                    errorData errorStruct = new errorData();
                    errorStruct.errorI = 1;
                    errorStruct.errorObj = "Stitle";
                    errorObjList.Add(errorStruct);
                    errorStrList.Add("此分类已存在");
                    i++;
                }


            }
            errorStrList.TrimToSize();
            errorStr = new string[errorStrList.Count];
            errorStrList.CopyTo(errorStr);
            #endregion
       
            #region ==通过验证==
            if (errorStr.Length == 0)
            {
            


                #region ==修改数据==
                m = new Model.productSort();
                m.d_Psid = Psid;
                m.Stitle = Stitle;             
                Bll.productSort.Modify(m);
                #endregion                            


                #region ==页面转向==
                Common.Functions.Alert("修改成功!", "productSortList.aspx?" + Common.Functions.transParameters("id"), true);
                #endregion
            }
            else
            {
                errorObjList.TrimToSize();
            }
         #endregion


        }
        #endregion


    }
 
    public string showErrorObj()
    {
        string str;
        str = "<script language=\"javascript\">";
        for (i = 0; i < errorObjList.Count; i++)
        {
            errorData t = (errorData)errorObjList[i];
            str += "markObj(form1." + t.errorObj + "," + t.errorI + "," + i + ");\n";
        }
        str += "</script>";
        return str;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值