I am building a site with WebMatrix using the razor syntax in .cshtml files. However I'm stumped as to how I can use the normal set of asp.net controls that are found in the toolbox in Visual Studio - eg: calendar, panel, radio button list etc... Is it possible to use these or can you only use Helpers with razor?
You cannot use ASP.NET controls with razor / .cshtml.
ASP.NET controls work with the ASP.NET WebForms view engine. Razor is a fundamentally different view engine than web forms.
If you really want to use the 'old' controls, switch to .aspx pages. If that's not an option, look into a UI library like jQuery UI. That should give you a similar set of controls.
Note that in razor a lot of controls like radio button list are obsolete. It takes just a few lines of markup to create the same behavior, without the databinding hassle though.
As an alternative tool, you can use Telerik Tabstrip and pass your .csHtml file as a partial view to it.
Some thing Like this:
#{ Html.Telerik().TabStrip()
.Name("TabStrip")
.Items(tabstrip =>
{
tabstrip.Add()
.Text("My First tab")
.Action("Index", "ControllerName")
.ImageUrl("~/Content/Common/Icons/Suites/mvc.png")
.Content(
#Html.Partial("csHtmlName_1", (List<TypeOfYourData>)ViewData["NameOfrelatedView"]).ToString()
);
tabstrip.Add()
.Text("My Second Tab")
.Action("secondAction", "ControllerName")
.ImageUrl("~/Content/Common/Icons/Suites/sl.png")
.Content(#Html.Partial("csHtmlName_2", (List<TypeOfYourDate>)ViewData["NameOfrelatedView"]).ToString()
);
})
.SelectedIndex(0)
.Render();
}
Please note that you need to install MVC Telerik first.(It's free :) and OpenSource)
You can't use Server Controls in ASP.NET Web Pages. It has been designed as an alternative to Web Forms.
You can use plain HTML or you can use the range of HTML helpers which work in a similar way to the ones in MVC (without the ModelBinding).
Related
I want to use only jquery ui controls in my web app and handle the raised events of controls in my c# code (not in javascript). I'm new in web programming so sorry if my question is too dummy. Also i want to design my web form with jquery controls as i do it with web controls from toolbox. Is it possible?
Or is there any alternatives to create beautiful ui in asp net web forms ?
You can use any controls you want. However, non asp.net controls will not postback to your server. You will need to manually call the __doPostBack(); asp.net method using javascript. Also, since none of you controls will be wired to do postbacks using the built in asp.net mechanism, you will need to force your page to generate that code for you by calling something like this:
var cs = Page.ClientScript;
cs.GetPostBackEventReference(this, string.Empty);
I hope this helps
I am trying to use underscores templating system in my project. Now the issue is that we have a lot of server side (ASP.NET) controls as well that I would like to use. Is there any way to use the ASP.NET controls together with underscore templates?
I tried simulating a template as an aspx page to get the rendered html from there and then use the result but that seems like an overkill.
I am pretty new to templating so I have no idea about what to expect.
EDIT:
What I meant was, is there any way I can have e.g. an ASP.NET button inside an underscore template?
The issue isn't with ASP.NET Controls (which use the runat="server" attribute), but with ASP.NET's Render function syntax <% %>.
See this earlier QA: How to use underscore/javascript templates in ASP.Net MVC views the solution is to configure underscore.js to use a different delimiter:
This:
_.templateSettings = {
interpolate: /\{%=(.+?)%\}/g,
escape: /\{%-(.+?)%\}/g,
evaluate: /\{%(.+?)%\}/g
};
...will let you use {% %} as delimiters instead of <% %>.
I just thought that it might help someone. One of the controls I wanted to use was a devexpress grid in my view. Now I could have done a "view source" on the grid and copied the rendered html to generate the view. However, I decided to create an aspx page and did an ajax call to the aspx page and displayed the resultant html in the view. I was hoping there would be a better way to do this.
I'm using VS 2010. Is there a way to "deploy" a user control and it's code behind in a sort of binary (.ocx like) way so that I can just reference it from other projects and the html/code behind can't be edited?
No, you either cut and paste or look into using custom Server Controls. The custom server controls are basically a way of building the same .ascx style controls but doing it all in code without a UI portion. If done correctly, you can still have a UI drag and drop interface for your controls.
http://msdn.microsoft.com/en-us/library/zt27tfhy(v=vs.100).aspx
As ps2goat said, what you want are custom server controls. That being said, there is a way to create them from standard ascx controls with only some extra effort.
http://msdn.microsoft.com/en-us/library/aa479318.aspx
It should be possible (though not recommended) if you place .NET code into ASCX markup itself inside of <script runat="server"></script> tags.
Does ASP.NET MVC4 has anything to do with multi-browser compatibility limitations?
In other words: the ASP.NET MVC engine also generates HTML server side which is displayed client side (right??), does it generate "non multi-browser compatible" HTML markup or do those two things have nothing to do with each other?
ASP.NET MVC framework doesnt generate HTML by itself, it use view engines to create HTML like: RAZOR, ASPX, SPARK and etc.
No , asp.net MVC does not magically generate any html. it render wherever you put in your views.
you will have to write your code to be "multi-browser compatible".
I'm about to start work on a new mvc3 razor web application. I'd like to use Ext.Net in this application, but ext.net works using a set of compiled user controls that basically wrap the ExtJs UI suite.
There is an ext.net mvc example you can download that uses MVC2 with the default asp.net view engine, it's not pleasant in that it looks very much like old-skool webforms code inside the view, but it works:
Inside a view/master:
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
...
<ext:ViewPort ID="ViewPort1" runat="server" Layout="border">
<Items>
<ext:Panel ID="Panel1"
runat="server"
...
Ideally, I want to use MVC3 for my new application, and I'm very keen to move to razor. But obviously, this isn't going to work since I'm rendering user controls in the view.
I don't know if/when the ext.net guys will port the product for mvc view engines, but in the meantime is there a solution.workaround that I could use to achieve the same thing? (I'd rather not use use ExtJS directly - I'm looking to expedite delivery and ext.net seems much easier)
Currently Ext.NET will not work with Razor, although it will function perfectly fine within the default MVC viewengine.
Coincidently, right at this moment, the next release of Ext.NET is being worked on, and it will fully support all MVC view engines. I know that does not help you right now, but might be of interest for a future project.
#jfar - Ext.NET does not depend/rely on ViewState and will render within ASP.NET MVC views.
You simply cannot take controls that depend on ViewState and make them work with MVC without extensive refactoring.
One option is to make non-MVC pages and include them in your app. WebForms and MVC can play nicely together.