除了使用OnLoad事件在ASP.Net MVC视图?视图、事件、OnLoad、ASP

2023-09-03 05:26:57 作者:累世情深

我要创建一个简单的测试应用程序,这样我可以看到ASP.Net MVC如何为我们处理每天。我们使用来自开发者的前preSS第三方控件,我们将继续使用它们。如果他们绝对不会在ASP.Net MVC的工作,那么我们将不会使用ASP.Net MVC。

I'm creating a simple test application so I can see how ASP.Net MVC works for what we deal with on a daily basis. We use 3rd party controls from Developer's Express, and we will continue to use them. If they absolutely do not work in ASP.Net MVC, then we will not use ASP.Net MVC.

随着中说,有人已经找到了一种方法,使其工作。他只是把一些code在code后面。他不得不重写OnLoad事件,简单地只是把grid.DataSource =模型和grid.DataBind(),它工作正常。

With that said, someone has found a way to make it work. He just had to put some code in the code behind. He had to override the OnLoad event and simply just put grid.DataSource = model and grid.DataBind() and it works as expected.

在ASP.Net MVC RC,隐藏文件code被淘汰。我知道我可以将它们放回......然而,由于人们一般说,隐藏文件code是邪恶的,你怎么还能做到这一点?

In the ASP.Net MVC RC, code behind files were eliminated. I know I could put them back in... However, since people generally say that code behind files are evil, how else could you accomplish this?

推荐答案

而无需创建一个codebehind文件的最简单方法是添加在你的.aspx页面这在任何地方:

The simplest way without creating a codebehind file is to add this anywhere on your .aspx page:

<script runat="server">
  private void Page_Load(object sender, System.EventArgs e)
  {
     //Initialize your control.
  }
</script>
 
精彩推荐
图片推荐