• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

.NET 秘籍

开发技术 开发技术 4小时前 1次浏览

textbox 只能输入数字

onkeypress="if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false;"

 

验证文本框

        function checknumber() {
            if ($.trim($('#<%=txt_number.ClientID%>').attr("value")) == "") {
                $('#<%=txt_number.ClientID%>').focus();
                alert("请选择人数!");
                return false;
            }
            else {
                return true;
            }
        }

 

去掉字符串的最后一个字符

.depId[0..^1];  //新写法
.Substring(0, depId.Length - 1);
.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

 

格式化时间

DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");  //最常用的日期格式

DateTime.ParseExact("1805", "yyMM", CultureInfo.InvariantCulture).ToString("yyyyMM");  //自定义格式化日期

//格式化开始时间,结束时间 DateTime.TryParse   if (!string.IsNullOrEmpty(DateStart)) queryString += ""release_time_begin":"" + Convert.ToDateTime(DateStart).ToString("yyyyMMddHHmmss") + "","; if (!string.IsNullOrEmpty(DateEnd)) queryString += ""release_time_end":"" + Convert.ToDateTime(DateEnd).ToString("yyyyMMdd") + "235959",";

 

Urlcode

var importExcel = encodeURIComponent($("#iptImportExcel").val());//前端
//后端
Session["SheetSplitConfigImportExcel"] = Request.QueryString["SheetSplitConfigImportExcel"] != null ? HttpUtility.UrlDecode(Request.QueryString["SheetSplitConfigImportExcel"]).ToString() :""; 

 

将类返回的对象转换为Json

public class json
    {
        public bool success { get; set; }

        public object msg { get; set; }

        public object Value { get; set; }

    }
  resXAML = JsonConvert.SerializeObject((new json { success = false, msg = err, Value = "Exception" }));

 

进行16进制计算

string cardNo = Convert.ToString(Convert.ToInt32(info.BZ3), 16).ToUpper().Trim();

 

Post和Get请求

//GEY请求
request.Method = "GET"; HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" ); req.Method = "GET"; using (WebResponse wr = req.GetResponse()) { } //post string param = ""; byte[] bs = Encoding.ASCII.GetBytes(param); HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" ); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = bs.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); }

//完整接受返回参数Post请求

public String RGetPageCode(String PageURL, String Charset)

{

        String strHtml = “”;

        ASCIIEncoding encoding = new ASCIIEncoding();

        //byte[] bytes = Encoding.UTF8.GetBytes(Charset);

        byte[] bytes = encoding.GetBytes(Charset);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(PageURL);

        request.Method = “POST”;

        request.ContentLength = bytes.Length;

        request.ContentType = “text/xml”;

        using (Stream requestStream = request.GetRequestStream())

        {

            requestStream.Write(bytes, 0, bytes.Length);

        }

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)

        {

           // strHtml = String.Format(“POST failed. Received HTTP {0}”,response.StatusCode);

            if (response != null)

            {

                if (response.StatusCode == HttpStatusCode.OK && request.HaveResponse)

                {

                    using (StreamReader sr = new StreamReader(response.GetResponseStream(), encoding))

                    {

                        if (sr != null)

                        {

                            strHtml = sr.ReadToEnd();

                        }

                    }

                }

                response.Close();

            }

        }

        return strHtml;

}

 

请求页面返回内容

protected void Page_Load(object sender, EventArgs e)
{
    string result = "";
    string userName = Request.Form["UserName"];
    string password = Request.Form["Password"];
    if (userName == "admin" && password == "123")
    {
        result = "登陆成功";
    }
    else
    {
        result = "登陆失败";
    }
    Response.Write(result);
}

 


程序员灯塔
转载请注明原文链接:.NET 秘籍
喜欢 (0)