除了使用OnLoad事件在ASP.Net MVC视图? [英] Alternative to using the OnLoad event in an ASP.Net MVC View?

查看:118
本文介绍了除了使用OnLoad事件在ASP.Net MVC视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个简单的测试应用程序,这样我可以看到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>

这篇关于除了使用OnLoad事件在ASP.Net MVC视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆