似乎存在三种不同的存储变量的方法,这些变量可用于应用程序中的每个请求:
的Global.asax.cs
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
Application["SiteDatabase"] = new SiteDatabase();
}
}
Run Code Online (Sandbox Code Playgroud)OWIN:
public partial class Startup
{
public void ConfigureAuthentication(IAppBuilder Application)
{
Application.CreatePerOwinContext<SiteDatabase>(new SiteDatabase());
}
}
Run Code Online (Sandbox Code Playgroud)静态容器
public static class GlobalVariables
{
private SiteDatabase _Database;
public SiteDatabase Database
{
get { return _Database ?? new SiteDatabase(); }
}
}
Run Code Online (Sandbox Code Playgroud)每种方法的相对优势是什么?
我试图获得一个cbxSupplement触发器updatepanel刷新,但我不确定我是否使用了错误EventName或者它是不可能的CheckBox.如果我更换CheckBox用Button,它工作正常.
<asp:Repeater ID="repSupplements" runat="server">
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbxSupplement" />
</ItemTemplate>
</asp:Repeater>
<asp:UpdatePanel runat="server" ID="up1">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="repSupplements" EventName="CheckedChanged" />
</Triggers>
<ContentTemplate>
//Get checked items
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)