我今天的收获(你的论坛,我做主)

1-----------------------------------------Session的生存期?

当客户端的浏览器关闭后,该session好像不会马上失效,而是当30分钟后才被destory(如果timeout设成30分钟)。

 

2----------------------------------------A页面嵌套B页面 A如何创建B的事件 

 我在A 加Button1控件
在B HTML中加 <%@ PreviousPageType VirtualPath="~/a.aspx" %>
public partial class b : System.Web.UI.Page
{
    public a c;
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        Response.Write(((Button)c.Page.FindControl("Button1")).Text);

    }
}

 

3-----------------------------------------数据库加锁

事务机制,就不会这样问数据库“锁”了。

例如对于SQL Server来说,你可以显示地使用那个Transaction来Commit和Rollback,即使不使用那么数据库也会对每一个sql语句自动地创建一个事务,根本没有那种问题。

 

4-------------HttpCookies oldCookie = Request.Cookies["userIP"];
                  HttpCookies newCookie = new HttpCookie("userIP");
                  问题是对于参数userIP在这里分别表示啥意思;加[]和()区别是啥? -------------------------------

 

HttpCookie c = new HttpCookie("dayfrom");
                c.Value = dayfrom;
                c.Values.Clear();
                c.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(c);

取Cookie值时就这样写
Request.Cookies["dayfrom"].Value

 

5----------Session["name"] = txtUserName.Text;
              btnRegister.Text
= "注册成功!3秒后转向首页```";
              System.Threading.Thread.Sleep(
3000);
               Response.Redirect(
"default.aspx"); -----------------------------------------------------------

 

服务器还没运行好,客服端怎么能显示btnRegister.Text = "注册成功!3秒后转向首页```";
所以直接Response.Redirect("default.aspx");

 

6----------ASP.NET中如何获取本机外网IP的所在地

  protected void Page_Load(object sender, EventArgs e)
    {

    Response.Write( SqlStringFormat.GetQuotedString(Request.UserHostAddress.ToString()));//获取IP
    }
    public class SqlStringFormat
    {
        /// <summary>
        /// 公有静态方法,将文本转换成适合在Sql语句里使用的字符串。
        /// </summary>
        /// <returns>转换后文本 </returns>
        public static String GetQuotedString(String pStr)
        {
            return ("'" + pStr.Replace("'", "''") + "'");
        }
    }

7------------------用一句SQL语句实现,找出表A中31-40条记录,(id号可能不连续)

  解1:select top 10 * from A where id not in (select top 30 id from A) 
  解2:  select top 10 * from A where id > (select max(id) from (select top 30 id from A )as A)

8---------------------怎么清除aspx页面所有TextBox的值

 protected void Page_Load(object sender, EventArgs e)
    {

    }
    public static void ClsTextBoxValue(Control Page)
    {
      int i=1;
        foreach (Control ctl in Page.Controls)
        { 
            string k="TextBox"+i.ToString();
          if (((TextBox)ctl.FindControl(k)).Text!=null)
            {
                ((TextBox)ctl.FindControl(k)).Text = string.Empty;
            }
            i++;
        }


    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        ClsTextBoxValue(Page);
    }
}

9--------------------------Server.Transfer方法在页面间传值

需在b.aspx HTML页中加 <%@ PreviousPageType VirtualPath="~/a.aspx" %>
然后在b.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 b : System.Web.UI.Page
{
    private a c;
    protected void Page_Load(object sender, EventArgs e)
    {
        string b = c.name;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值