Hi I am just learning about C# can anyone recommend a site I can look at and look at the development side of the site to show me just how the C# language is applied to the site. Eg. is it just added to the HTML like JS or how is it worked into the coding. I just can't get my head around how it comes together with HTML, CSS and C#.
Thanks Linda
Creating web applications with C# comes in 2 flavors. Web forms applications and MVC applications. Web forms is the oldest and was the first. It works based on events. You would design a form or a "page", drag controls onto the page (such as a text box or a button), then wire them up to do something based on some event. For example, if you had a button on your application, you would respond to the Click event. The events were server side and would cause a post back. After the post back, your event, such as Click would be executed. This code was in C#.
Because this event based program was cludgy and ugly and didn't really "flow" correctly with how web applications work, MVC came along. MVC (Model-View-Controller) works differently. When someone in their browser put in your URL (http://www.example.com), IIS would execute your controller that handles the page they are requesting. Your controller would optionally load data from a database, put it into a model, then pass the model to your view. The view is your UI and it receives data from the model and does "something". Any new web application you make these days will almost always be an MVC application.
I hope this helps!
Try the ASP.Net MVC framework.
http://www.w3schools.com/aspnet/mvc_intro.asp is a good tutorial to get you started with using it. It is slightly outdated, but still gives a good intro to how it integrates with HTML.
Related
I want to make a dynamic control on a web page that does an action and generates new HTML code without needing to refresh the page (what would traditionally be handled by JavaScript, I presume). However, my project is currently comfortably and neatly nestled in as a pure ASP.NET Web Pages project strictly using Razor, no MVC at all.
I've hunted everywhere and haven't gotten a clear answer; what answers I have found always concern deep MVC or Web Forms components. As I understand, it should be fairly easy to make use of bits and pieces of those, but I'm still fairly inexperienced with ASP.NET.
What I want to make in short: A button that
Is an image
When clicked, increments a record value (already stored in the Razor code, simple to push to the database), and replaces itself with another image button
This button has a different image, will decrement the record value and replace itself with the original button (they are effectively the inverse of each other)
This is the most complex control I need at the moment for my project, and learning about this will hopefully provide a basis from which to engineer different controls.
The underlying technology of the server is irrelevant, whether it's PHP, ASP.NET, Ruby, et cetera - if you want a web page to "do something", you need to send a request to the server. If you want it to do something without the user directly submitting a form or clicking on a link and changing their location, you have to send the request to your server with javascript. Javascript is how you get the client to do things. The razor templating system operates on the server, not on the client.
Specifically, you should look in to Javascript AJAX requests; I'd particularly recommend learning about jQuery, because it simplifies a lot of aspects of Javascript.
OK so I have a webforms project I am wanting to start doing MVC instead. I would like the MVC pages to use the Webforms master page until I can get things transferred over more to MVC. I have this working with a solution I have found you can find listed below (This project works really well except the server event)
https://github.com/MicahArmantrout/BlackMagicMVC
My problem is that server side events in the master page are not firing. When you load the project up if you click on "Click Me!" the button will fire a server event and the Text will change to "You clicked me".
If you goto "Click For MVC" (Which is a MVC Partial Render) and then click the "Click Me!" the server event never fires. Any idea why and if this can be fixed ?
Note: This is not just a exercise I have a place in a application where this would be extremely useful.If you want to understand this project more please see
http://trycatchfail.com/blog/post/ASPNET-MVC-3-Razor-C-and-VBNET-WebForms-A-Tale-of-Black-Magic-Voodoo.aspx
There is no concept of server side events in MVC. And MVC is not going to wire up the client side events and translate them to server side event handlers the way ASP.Net WebForms does.
You have these options:
Recreate master page in MVC (_Layout.cshtml) and then handle button clicks in your controller. Depending on your design, some refactoring would be needed. You need to decide how or who handles those button clicks. You can probably get away with handling some of them in a Base Controller, but I would suggest to take a second look at what you're doing in master and how you can translate them on MVC.
Do the other way round - define you master page in MVC, and render that in your webforms.
Ideally, your master page should not be having any business functions anyway. It should be nothing more than Navigation and style. As long as you adhere to this, migrating to MVC won't be that painful.
I am developing web browser in C# windows form application using WebBrowser component.And also a website in ASP.NET using C#.Both are different projects.How can i use value of Label from windows form application and use the same value in ASP.NET website?
Help me !
Thanks in advance !!
Did you know you can write code to automate browsers, such as IE or Firefox? I mean, write code to launch a browser window, load pages at will, easily access particular parts of web pages, simulate user input (textboxes, controls, buttons, etc). It's commonly used to automate testing of web pages, and what-not.
There are multiple libraries out there, but I personally tried WatIn: http://watin.org/. Open source (free), .net component, easy to use, ton of examples.
I'm suggesting this as an alternative - if it fits your model. I know this doesn't answer your question; sorry.
I'm trying to learn about how AJAX stuff works under the hood. Say I have an asp.net form with a button on it. I then have a database with a single column DateTime. When I click the button on the asp.net form I want to insert a column in the database with the current time.
I'll have a C# event handler:
protected void btnButton_OnClick(Eventargs e, object sender)
{
//insert DateTime.now into DB
//This part is easy
}
What I would like to happen on the form itself is to have the button click NOT reload the form. It would just send a message to the server; there is no reason for the page to reload. What are some ways I could accomplish this?
I've looked into the AJAX framework a little bit and it seems like this could be done within an update panel, but the page would still reload, it would just be less noticable to the user.
Use the __doPostBack call in javascript. I have no idea how this works.
It sounds like you're partial to Microsoft's provided javascript libraries, which is fine. The UpdatePanel and the like have their place, but I've found that when you need to do something very simple and straightforward like what you're describing it is easier and cleaner to get it done with a direct call to a server resource from Javascript.
There are many ways to do this, but I like using jquery's $.ajax() method to invoke webservice methods (or MVC actions more recently). If you're willing to examine some slightly different technologies here's a blog post that will give you a taste of what I'm talking about.
ASP.NET Ajax has 2 major parts:
server side controls based
client side framework (which is called Microsoft Ajax)
With the first you would opt to make use of an UpdatePanel control. This however still sends a lot of unneeded data over the wire like the full viewstate, your pages follow almost the full page life cycle like with a normal postback. Mostly I recommend against using that in production code.
The second part is an ajax library based on pure javascript with a touch of Microsoft sauce over it. It has similarities with the page life cycle like a pageLoad function and such and is quite easy to learn.
__doPostBack
That function gets inserted when you place certain server controls on your page like a LinkButton control. You can call that from javascript directly but know that it'll cause a full page postback to the server so if you want to avoid that don't go that path.
During the last 2 years however I've become a big fan of jQuery which works quite well together with ASP.NET and ASP.NET MVC.
I suggest that you read this fine article to get more information about it: Using jQuery with ASP.NET Part 2: Making an AJAX Callback to ASP.NET.
jQuery itself has also been adopted and favored by Microsoft. I strongly suggest you take a look at it and its power.
I have an ASP MVC application which uses some silverlight applications in the View. By now, I hava a map, that, when a State is clicked, redirects to the related page. Now, I need a silverlight application in which state, with the state map and the location of the harbors on this state (you chose a state in the first map, than you get redirected to the chosen state, where you can select a harbor that will be highlighted in a table - not sure how I'll achieve that yet). Which type of class should I use to this new silverlight map of each state? Is it easy to do what I want? (I created an user controller class, but expression blend couldn't open it, don't know why).
It sounds like all your Silverlight controls are so similar in function that a single Silverlight application would do.
You can pickup the host-page url from within Silverlight and therefore use url parameters to determine what to display.
You also have options of communicating via Javascript to exposed methods on your Silverlight application and also the reverse (executing Javascript from the Silverlight app).
Not sure why you had problems with Blend without seeing the offending user control.
Hope this helps.