Timers from ASP.NET to MVC Razor - c#

I'm moving an app from ASP.NET/C# to MVC and I have some Timers <asp:Timer>
I'm trying to find exactly the same tool for MVC (Html5 or DevExpress) but seems like there is not or at least my intellisense doesn't show it.
Anyone knows about it and can post the squema of it?

You will need to use Javascript yourself.
Take a look at window.setInterval() or one of the many jQuery timers.

Another option, that doesn't involve javascript is the HTML META tag.
example:
<meta http-equiv="refresh" content="30">
content is specified in seconds. META elements live within the HEAD element.

Related

Building SPA application. Is calling RenderBody necessary?

I'm building SPA application using Backbone.js and as its back-end I want to use ASP.NET Web API. I need only one page and this fact brings me a lot of confusion.
ApiController returns json response and as far as I understand there's no need in asp.net-specific views at all. Am I right?
Can I use plain html for my main page? Or should I use *.cshtml and put a call to RenderBody instead?
If choose the first option then how will I handle validation?
Thanks!
Well the trick is that if you want search engines to be able to index your page, or people to be able to share to Facebook with a custom icon/description, etc you'll need to serve back static HTML -- none of those bots are able to run your javascript to render the page as the browser does.
If you're uninterested in this, then yes, you can completely avoid RenderBody.

Use Wordpress Template in c# project

There are plenty of Wordpress template out there, most of them are well designed.
I like to know, is there a way to easy to use Wordpress template in c# project.
Is there any out-of-the-box solution?
Just grab a copy of the output HTML and the CSS of the WP site and apply/build your ASP.NET site around it. This is straightforward in itself. Where most people get confused is when there's a master page in the mix in ASPNET; however, this is not a problem. Just start (with the HTML produced by the WP site) by creating the main divs working from the outside-in, using the master page and then content areas in your pages. Master page(s) will generally contain display elements common to all or a subset of pages.
No, there is nothing "out-of-the-box".
You will need to write your own converter if you wish to do this, though translating a single page shouldn't be too difficult.

How to refresh just a specific portion of an HTML page?

I have one HTML file containing several <div> elements. I want to refresh just part of the page using either JavaScript or C#. Can someone help?
I am trying to do it this way:
document.location.reload(document.getElementById("contentdiv"));
It reloads the whole page. I wish to reload contentdiv. If contentdiv is at the middle of the page then it should load only that part.
Thank you.
You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax.
Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier.
iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame.
Not sure if this is what you're looking for, but hope it helps somewhat.
What ASP.NET Framework are you using? If you are using Web Forms, look into UpdatePanel

How should I handle multiple links ot the same page with different Query Strings

In the website I am working on, there is a product page with 8 tabs on it, showing different aspects of the product. There are quick links on other pages within the site that take you to the page and to a specific link specified by a query string.
For example the base page would be www.example.com/Product1. And then there are links like this:
www.example.com/Product1?tab=CADDrawing
www.example.com/Product1?tab=Schematics
www.example.com/Product1?tab=Reviews
My concern is that Google sees each of these links as a different URL but they aren't and the data on the page is 100% the same. Is there any easy way to make it so Google either knows that www.example.com/Product1 is the base page or doesn't follow the links with Query Strings?
I thought about using rel="nofollow" but that seems like it would actually hurt my page ranking. Most of the websites, including Googles on webmaster pages, is unclear.
The other option is to add the rel="canonical" to the pages that have a query string but not to the base page. Does that succeed in stopping all of the noisy links?
Using a link tag with a canonical URL in the head of the product page should do the trick:
<link rel="canonical" href="www.example.com/Product1" />
There is a base-tag in html:
<head>
<base>www.example.com/Product1</base>
</head>
Maybe that will indicate to google that its all the same page? This is just a wild assumption though, no idea how google will handle it.

Rendering "partial" pages in ASP.Net? (without the <html> and such)

I am trying to make use of jQueryUI AJAX tabs in my ASP.Net Webforms project.
I have come up against a wall though. For AJAX, you must render only a partial page(no <html> and such elements) by an external URL. How would you best do this in ASP.Net? aspx files require things like a <html> and <head> tag so those wouldn't work so the only thing that comes to mind is using cumbersome ashx files. Am I just over thinking this? Is there an easier way?
Edit:
So apparently <html> and such tags are not actually required. So what differences are there to rendering without the full page headers? Will some controls not work? Why wouldn't they?
There's no reason your .aspx pages have to have <html> tags.
Just go ahead and build .aspx pages with the content you want on them and point your jQuery UI tabs to each URL and it will wire up nicely.
ASP.Net does not require any particular HTML tags.
You can make a partial page as an ASPX that includes whatever you want. (Although some server-side controls might not work)
In fact, you can even make an ASPX page that renders aribtrary (non-XML) plain text.

Categories