Session_start未运行

时间:2015-08-13 01:39:49

标签: c# asp.net

我刚开始用C#教自己dotNet并遇到了问题。基本上我有一个我想要在首次加载页面时初始化的变量。我试过使用Session_Start来做到这一点。然而,当我在那个时候设置一个断点时,它似乎永远不会到达那里。

我不理解的是什么?

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    int numTries;

    protected void Session_start(object sender, EventArgs e)
    {
        numTries = 3;
    }

    protected void CheckNum_ServerClick(object sender, EventArgs e)
    {
        if (numTries>0)
        {
            numTries--;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Answer.InnerText = "You have "+numTries.ToString()+" changes left.";
    }
}

HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Guess a number between 1 & 100 &nbsp;
        <input type="text" id="Guess" runat="server" />
        <br /><br />
        <input type="submit" value="OK" id="CheckNum" runat="server" onserverclick="CheckNum_ServerClick" />
        <br /><br />
        <p id="Answer" runat="server"></p>
    </div>
    </form>
</body>
</html>

我正在使用Visual Studio Community 2013

0 个答案:

没有答案