wanting-yy  

login.aspx

<input type="text" name="txtVerifyCode" id="txtVerifyCode" class="yanin" maxlength="4" runat="server" /></div><div class="yanzheng2"><asp:Label ID="lblCode" runat="server"></asp:Label></div>

login.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
                        RndNum();
        }
    }

 private string RndNum()
    {
        string[] textArray = new string[] {
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f",
        "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
        "w", "x", "y", "z"
         };
        string text = "";
        Random random = new Random();
        for (int i = 0; i < 4; i++)
        {
            text = text + textArray[random.Next(0, textArray.Length)].ToString() + " ";
        }
        Session[configInfo.CachePre + "VerifyCode"] = text.Replace(" ", "");
        lblCode.Text = text;
        return text;
    }

posted on 2010-12-17 00:33  wanting-yy  阅读(107)  评论(0)    收藏  举报