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;
}
}
10-----------------------------数据库语句
存储过程
create Proc Canton_GetOne
@CtID int
as
select * from book where id =@CtID
GO
用户自定义函数
create FUNCTION GetCtCode_ReturnCtID(@CtCode nvarchar(50))
RETURNS int AS
BEGIN
DECLARE @i int
select @i=id from book where name= @CtCode
RETURN @i
END
执行语句
exec Canton_GetOne @CtID=dbo.GetCtCode_ReturnCtID('a')
declare @b int
set @b = dbo.GetCtCode_ReturnCtID('a')
exec Canton_GetOne @b