62,268
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
string js = "<script>alert('您未登陆,无法操作');</script>";
if(Session["name"] == null)
{
ScriptManager.RegisterStartupScript(Updatepanel1, Updatepanel1.GetType(), "Startup", js, false);
Response.End();//这句如果不加的话,是可以有提示框的
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string js = "<script>alert('您未登陆,无法操作');</script>";
if(Session["name"] == null)
{
ScriptManager.RegisterStartupScript(Updatepanel1, Updatepanel1.GetType(), "Startup", js, false);
}
else
{
//功能代码
}
}
<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Label ID="lblmsg" runat="server" Text=""></asp:Label>
<asp:Label ID="lblmsg2" runat="server" Text="Error Message" Visible="false"></asp:Label>
protected void Button1_Click(object sender, EventArgs e)
{
Session["msg"] = txtTest.Text.ToString();
//如果为空,则将原隐藏的Label显示出来.
if(string.IsNullOrEmpty((string) Session["msg"]))
{
lblmsg2.Attributes["Style"] = "display:block";
//为空时的处理代码
// ...........
}
else
{
lblmsg.Text = "Hoho Succeed";
//满足条件的处理代码
// ..........
}
}
//App_Code/lib.cs类文件中:
static public bool CheckLogin(Updatepanel1)
{
string js = "<script>document.all.logindiv.style.display = 'block';</script>";
if(Session["name"] == null)
{
ScriptManager.RegisterStartupScript(Updatepanel1, Updatepanel1.GetType(), "Startup", js, false);
return false;
}
return true;
}
主程序中
protected void Button1_Click(object sender, EventArgs e)
{
if(CheckLogin(UpdatePanel1))
{
string sqlcmd = "insert into message (title) values (@title)";
//后面就是接下去的往数据库里写记录的代码了
}
}
App_Code/lib.cs类文件中:
static public void CheckLogin(Updatepanel1)
{
string js = "<script>document.all.logindiv.style.display = 'block';</script>";
if(Session["name"] == null)
{
ScriptManager.RegisterStartupScript(Updatepanel1, Updatepanel1.GetType(), "Startup", js, false);
Response.End();//如果这里用Return的话,只是返回到主程序中,并没有中断主程序以后的执行
}
}
主程序中
protected void Button1_Click(object sender, EventArgs e)
{
CheckLogin(UpdatePanel1);
string sqlcmd = "insert into message (title) values (@title)";
//后面就是接下去的往数据库里写记录的代码了
}
App_Code/lib.cs类文件中:
static public void CheckLogin()
{
string js = "<script>document.all.logindiv.style.display = 'block';</script>";
if(Session["name"] == null)
{
ScriptManager.RegisterStartupScript(Updatepanel1, Updatepanel1.GetType(), "Startup", js, false);
Response.End();//如果这里用Return
}
}
主程序中
protected void Button1_Click(object sender, EventArgs e)
{
CheckLogin();
string sqlcmd = "insert into message (title) values (@title)";
//后面就是接下去的往数据库里写记录的代码了
}