requirements are as follows:
1. Template page to the right contains a landing div, want to let not log in when this div display, after landing the Div hidden
2. Display a welcome user Div, mainly want to hide through JavaScript
Note: You cannot use RegisterClientScriptBlock to register and execute Javascrip in a template page.
So the registration and execution of JavaScript is done on the page page.
content in main.master template page
Copy Code code as follows:
<!--login Small div-->
<div class= "Logindiv" >
<div class= "Logindivtitle" >
Member Login
</div>
<table class= "Logintable" >
<tr>
<TD class= "Loginlabel" > Username:</td>
<td><input type= "text" class= "Logintxt" id= "txtUserName"/></td>
</tr>
<tr>
<TD class= "Loginlabel" > Password:</td>
<td><input type= "Password" class= "Logintxt" id= "Txtpass"/></td>
</tr>
<tr>
<TD class= "Logintdbuttons" colspan= "2" >
<input src= ". /images/az-login-gold-3d.gif "type=" "image" Id= "Btnlogin"/>
<input src= ". /images/az-newuser-gold-3d.gif "type=" "image" Id= "Btnreg"/>
</td>
</tr>
</table>
</div>
<div class= "Loginokdiv" style= "Display:none" >
<span class= "Spanloginok" id= "Spanuserinfo" >
Dear <%=serverusername%>, Welcome to your visit!
</span>
</div>
<1> code in the background main.master
Copy Code code as follows:
protected string Serverusername;
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Model.users user = session["Curruser"] as model.users;
if (user!= null)
{
Serverusername = user. Name;
}
}
}
<2>mainpage The background code in the main page, which is inherited from the template page Main.master
Copy Code code as follows:
public partial class MainPage:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Model.users user = session["Curruser"] as model.users;
if (user!= null)
{
Common.CommonCode.ExecuteScriptFunc (this,true);
}
Else
{
Common.CommonCode.ExecuteScriptFunc (This,false);
}
}
}
}
<3>executescriptfunc Package Code
Copy Code code as follows:
public static void Executescriptfunc (System.Web.UI.Page Page, BOOL Bshowuserinfo)
{
String func = "function Showuser (islogin) {\r\n\r\nif (islogin) {\ r \ n] +
" $ (\). logindiv\ "). hide (); \ r \ n" +
"$ (\". loginokdiv\ "). Show () \ r \ n" +
"}\r\n" +
"else {\ r \ n" +
"$ (\". logindiv\ "). Sh ow (); \ r \ n "+
" $ (\ ". loginokdiv\"). hide (); \ r "+
"} ";
String func1 = "";
if (bshowuserinfo)
{
Func1 = func + "\ r \ n" +
"$ (function () {\r\nshowuser (true)" +
"});";
}
Else
{
Func1 = func + "\ r \ n" +
"$ (function () {\r\nshowuser (false)" +
"});";
}
Page. Clientscript.registerstartupscript (page. GetType (), Guid.NewGuid (). ToString (),
Func1, True);
//page. Clientscript.registerstartupscript (page. GetType (), Guid.NewGuid (). ToString (),
//FUNC1);
}