meiwn

统计

常用链接

好的网站

阅读排行榜

评论排行榜

2006年10月25日 #

关于权限的一点学习

我认为权限是个比较复杂的东东,我写了个简单的代码,就是登陆后把此用户的权限列表读出来,放在一个hashtable里,并放到一个session中,用的时候就比较这个菜单或一个文件的权限是否在hashtable中,不知道这种想法对不对,希望大家提出意见

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 Default5 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    
protected void Button1_Click(object sender, EventArgs e)
    {
//表示是否登陆
        Session["username"= "admin";
        Hashtable ht 
= new Hashtable();
        ht.Add(
"调查管理""1");
        ht.Add(
"新闻管理""2");
        ht.Add(
"会员管理""3");
       
//权限表
        Session["popedom"= ht;
    }
    
protected void Button2_Click(object sender, EventArgs e)
    {
        
        Session.Abandon();
    }
    
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        
if (Session["username"]!=null)
        {
            
if (((Hashtable)Session["popedom"]).Contains("调查管理"))
        {
            LinkButton1.Text 
= "有调查管理权限";
        }

        }
        
else
        {
            LinkButton1.Text 
= "你没有调查管理权限";
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), 
"dd""alert('你没有调查管理权限');"true);
        } 
   
    }
    
protected void LinkButton2_Click(object sender, EventArgs e)
    {
        
if (Session["username"]!=null)
        {
            
if (((Hashtable)Session["popedom"]).Contains("新闻管理"))
            {
                LinkButton2.Text 
= "有新闻管理权限";
            }

        }
        
else
        {
            LinkButton2.Text 
= "你没有新闻管理权限";
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), 
"dd""alert('你没有新闻管理权限');"true);
        }

    }
}

posted @ 2006-10-25 10:25 努力学习.NET 阅读(94) 评论(1) 编辑

2006年10月24日 #

利用javascript改变背景色


<body leftmargin=5 topmargin=0  onmouseover="document_onmouseover();"onclick="document_onclick();" id="all" >

<SCRIPT LANGUAGE="javascript">
var curObj= null;
var curObjmouseover=null;
function document_onclick() {
if(window.event.srcElement.tagName=='A'||window.event.srcElement.tagName=='FONT'){

if(curObjmouseover!=null)
curObjmouseover.style.background
='';
if(curObj!=null)
curObj.style.background
='';


curObj
=window.event.srcElement;
curObj.style.background
='#ff0099';

    }
}

function document_onmouseover() {

if(window.event.srcElement.tagName=='A'||window.event.srcElement.tagName=='FONT'){
if(curObjmouseover!=null)
{curObjmouseover.style.background
='';
curObjmouseover.style.color
='#000000';}

if(curObj!=null)
curObj.style.background
='';

curObjmouseover
=window.event.srcElement;
curObjmouseover.style.background
='#cccc00';
curObjmouseover.style.color
='#ffffff';
    }
}
 
</SCRIPT>
<div>
 
<href='#'  >来自猫扑【原创】(7条)</a> </div>
<div>  <href='#'  >来自猫扑【原创】(7条)</a> </div>

posted @ 2006-10-24 16:14 努力学习.NET 阅读(5688) 评论(0) 编辑

2006年10月19日 #

利用正则表达式来反转一句话,以单词为单位

 public static int Main(string[] args)
        {
    

            Console.WriteLine(
"============================");
            
string s = "i'm a student,my name is yuhong!ok!!!";
 
            
string[] sArray = System.Text.RegularExpressions.Regex.Split(s, @"[^\w]+", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            
//记录标点符号
            string[] sArray2 = System.Text.RegularExpressions.Regex.Split(s, @"[\w]+",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            
int start = 0;
            
int end = sArray.Length - 1;
            
while (start<end)
            {
                
string tmp = sArray[start];
                sArray[start] 
= sArray[end];
                sArray[end] 
=tmp;
                start
++;
                end
--;
            }


            start 
= 0;
            end 
= sArray2.Length - 1;
            
while (start < end)
            {
                
string tmp = sArray2[start];
                sArray2[start] 
= sArray2[end];
                sArray2[end] 
= tmp;
                start
++;
                end
--;
            }
            
// s=string.Join(" ", sArray);
            string result = "";
            
for (int i2 = 0; i2 < sArray.Length; i2++)
            {
                result 
+= sArray[i2] + sArray2[i2];
            }


            s 
= result;
            Console.WriteLine(s);
            
//Console.WriteLine("============================");
            
//string str1 = "我**是*****一*****个*************教*****师";
            
//string[] str2 = System.Text.RegularExpressions.Regex.Split(str1, @"[*]+");
            
//foreach (string iss in str2)
            
//    Console.WriteLine(iss.ToString()); 
            return 0;
        }

posted @ 2006-10-19 13:45 努力学习.NET 阅读(225) 评论(0) 编辑

2006年10月14日 #

长文章的js分页

posted @ 2006-10-14 00:08 努力学习.NET 阅读(1304) 评论(2) 编辑

2006年10月5日 #

Asp.net中复合控件的一些学习心得

在.net 2.0中有System.Web.UI.WebControls.CompositeControl,使得编写的复合控件在使用时有更友好的界面
以前在做复合控件时最常见的是以下代码
public class LabelTextBox :WebControl, INamingContainer
{
public string Text {
get {
object o = ViewState["Text"];
if (o == null)
return String.Empty;
return (string) o;
      }
set { ViewState["Text"] = value; }
   }
public string Title {
get {
object o = ViewState["Title"];
if (o == null)
return String.Empty;
return (string) o;
      }
set { ViewState["Title"] = value; }
   }
protected override void CreateChildControls()
   {
Controls.Clear();
CreateControlHierarchy();
ClearChildViewState();
   }
protected virtual void CreateControlHierarchy()
   {
TextBox t = new TextBox();
Label l = new Label();
t.Text = Text;
l.Text = Title;
Controls.Add(l);
Controls.Add(t);
   }
}



重点是这一句public class LabelTextBox :WebControl, INamingContainer
继承了WebControl类和实现ImamingContainer了接口
但是这样做成的复合控件在使用时设计界面很不友好,在2.0中新增了一个System.Web.UI.WebControls.CompositeControl
这样在作用控件的时候就不会有设计的障碍了,代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CompositeControl
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:LabelTextBox runat=server></{0}:LabelTextBox>")]
    public class LabelTextBox : System.Web.UI.WebControls.CompositeControl
    {
        public string Text
        {
            get
            {
                object o = ViewState["Text"];
                if (o == null)
                return String.Empty;
                return (string)o;
            }
            set
            {
                ViewState["Text"] = value;
            }

        }
        public string Title11
        {
            get
            {
                object o = ViewState["Title"];
                if (o == null)
                    return String.Empty;
                return (string)o;
            }
            set
            {
                ViewState["Title"] = value;
            }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            CreateControlHierarchy();
            ClearChildViewState();
        }
        protected virtual void CreateControlHierarchy()
        {
            TextBox t = new TextBox();
            Label l = new Label();
            t.Text = Text;
            l.Text = Title11;
            Controls.Add(l);
            Controls.Add(t);
        }

    }
}


这是这样了,大家可以试试

posted @ 2006-10-05 15:49 努力学习.NET 阅读(288) 评论(0) 编辑

2006年10月4日 #

asp.net中实现下载

posted @ 2006-10-04 22:43 努力学习.NET 阅读(167) 评论(0) 编辑

2006年9月30日 #

ASP.NET 2.0客户端回调的实现例子

posted @ 2006-09-30 16:24 努力学习.NET 阅读(326) 评论(1) 编辑

2006年9月27日 #

GridView系列(一)排序列头加箭头

posted @ 2006-09-27 15:26 努力学习.NET 阅读(1583) 评论(3) 编辑

2006年9月23日 #

女人洞房那天

posted @ 2006-09-23 10:19 努力学习.NET 阅读(83) 评论(0) 编辑

ASP.NET程序中常用的三十三种代码

摘要: 1. 打开新的窗口并传送参数:

  传送参数:

response.write("<script>window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")
  接收参数:

string a = Request.QueryString("id");
string b = Request.QueryString("id1");
  2.为按钮添加对话框

Button1.Attributes.Add("onclick","return confirm(’确认?’)");
button.attributes.add("onclick","if(confirm(’are you sure...?’)){return true;}else{return false;}")
  3.删除表格选定记录

int intEmpID = (int)MyDataGrid.Da阅读全文

posted @ 2006-09-23 09:48 努力学习.NET 阅读(81) 评论(0) 编辑