I have been reading about ASP.NET MVC on ScottGu's blog. Excellent 4 part articles. I decided to give it a shot and bang.......... Can't go anywhere with it!!!!
I thought, I will use 2nd approach and can use all server side controls like TextBox, RadioButton, DataGrid, DataList, Buttons etc.
However I couldn't find any control id's in my codebind file.
Somehwere in this forum I saw a post where one mentions that right click on a page and convert it to web application. Wow, I can access all my control ids now. I saw a "form" tag on my content page which I converted into web application. I removed form tag
everything is still ok.
In the code behind I can say:
TextBox1.Text = ViewData.Name;
ddlState.DataSource = ViewData.States;
ddlState.DataBind();
But then, in entire article series Scott uses Inline Code. All the thread in forum says we can't use ASP.NET server controls.
Looks like I am completely lost.
- Can I use ASP.NET server control in MVC or not?
- What type of controls I can use on MVC ViewContentPage?
Some of the controls must have the <form runat="server"> such as the TextBox.. but some will not work becuase the postback will not call an action method of the controller, still use events, and the ViewState will not be used when an Action method is called
etc. Read the answers in the post I potined you to, and you will get all info you need.
Server controls that do not require ViewState to fully function will work in MVC, but anything that requires PostBack to work properly will not.
So bindable, read-only controls like the Repeater will work, but input controls like the DropDownList and TextBox will not.
I would recommend checking out the
MVCContrib project and using it's HTML Helpers to help you get things like bindable dropdownlists and input controls. You won't get postback functionality, but at least you can reduce the markup necessary for your pages.
This command will move all control declarations in your page to a designer file and add event handler declarations to the server-control markup in .aspx and .ascx files. You should not need this command in the context of an mvc application as it is only
used to convert legacy projects and website projects to web applications.
love_luv
Contributor
2256 Points
481 Posts
Confused!!!! ASP.NET MVC Framework and Use ASP.NET Server Control or not?
Feb 07, 2008 06:25 PM|LINK
I have been reading about ASP.NET MVC on ScottGu's blog. Excellent 4 part articles. I decided to give it a shot and bang.......... Can't go anywhere with it!!!!
Somewhere in the first article:http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx
Scott mentions 2 different rendering approach:
Rendering Approach 1: Using Inline Code
Rendering Approach 2: Using Server Side Controls
I thought, I will use 2nd approach and can use all server side controls like TextBox, RadioButton, DataGrid, DataList, Buttons etc.
However I couldn't find any control id's in my codebind file.
Somehwere in this forum I saw a post where one mentions that right click on a page and convert it to web application. Wow, I can access all my control ids now. I saw a "form" tag on my content page which I converted into web application. I removed form tag everything is still ok.
In the code behind I can say:
TextBox1.Text = ViewData.Name;
ddlState.DataSource = ViewData.States;
ddlState.DataBind();
But then, in entire article series Scott uses Inline Code. All the thread in forum says we can't use ASP.NET server controls.
Looks like I am completely lost.
- Can I use ASP.NET server control in MVC or not?
- What type of controls I can use on MVC ViewContentPage?
- How do I bind data to control in code behind?
Thanks !!!!!
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: Confused!!!! ASP.NET MVC Framework and Use ASP.NET Server Control or not?
Feb 07, 2008 06:38 PM|LINK
Take a look at the following post it's about what you are asking: http://forums.asp.net/t/1214040.aspx
Some of the controls must have the <form runat="server"> such as the TextBox.. but some will not work becuase the postback will not call an action method of the controller, still use events, and the ViewState will not be used when an Action method is called etc. Read the answers in the post I potined you to, and you will get all info you need.
MVP, ASPInsider, WCF RIA Services Insider
My Blog
webgambit
Member
2 Points
2 Posts
Re: Confused!!!! ASP.NET MVC Framework and Use ASP.NET Server Control or not?
Feb 07, 2008 06:41 PM|LINK
Server controls that do not require ViewState to fully function will work in MVC, but anything that requires PostBack to work properly will not.
So bindable, read-only controls like the Repeater will work, but input controls like the DropDownList and TextBox will not.
I would recommend checking out the MVCContrib project and using it's HTML Helpers to help you get things like bindable dropdownlists and input controls. You won't get postback functionality, but at least you can reduce the markup necessary for your pages.
gayupk
Member
26 Points
60 Posts
Re: Confused!!!! ASP.NET MVC Framework and Use ASP.NET Server Control or not?
Apr 28, 2008 06:07 AM|LINK
Can anybody tell me what exactly happens when I convert my page to web Application?Thanks in advance
joecar
Member
524 Points
120 Posts
Microsoft
Re: Confused!!!! ASP.NET MVC Framework and Use ASP.NET Server Control or not?
Apr 28, 2008 07:32 PM|LINK
This command will move all control declarations in your page to a designer file and add event handler declarations to the server-control markup in .aspx and .ascx files. You should not need this command in the context of an mvc application as it is only used to convert legacy projects and website projects to web applications.