I can easily localize any inline text by using
<asp:Localize runat="server" meta:resourcekey="LocalizeResource5" Text="Actions"></asp:Localize>
Is it possible to localize Html attributes directly in aspx code, without using code-behind or other “tricks”? (I mean: supported by Visual studio Resource files generator)
Example:
<input type="text" placeholder="text to localize" />
Thanks
After my experience with localizing quite few websites, I can tell you that ASP.NET localization system is pretty bad (would use some other word here... but must resist the temptation).
You've ran into one problem... for me the bigger problem was changing localized text without forcing user to reload the page.
So, what I would advise you is to ditch ASP.NET localization and switch to something way better, namely Angular-Translate.
Unlike ASP.NET localization system, Angular-Translate has seen WAY much more usage in production and most of the problems you'll run into have already been solved in the library. Plus, you can use it pretty quickly, without much AngularJs knowledge - just see getting started example.
Related
I am used to working with ASP web apps and creating .aspx pages. I don't know PHP really and I have worked a while with C# and ASP. I really like bootstrap so far and designing with it in HTML looks great and seems to work great. However, I am concerned that somehow this won't transfer over to ASP.
Twitter Bootstrap is just a bunch of CSS/JS files. So it works with every web technology out there.
Another thing is that ASP.NET (at least, old one, before MVC) is relying heavily on server controls. So it could be problematic to apply twitter stylesheets and behaviour to asp.net server controls. I don't know if it got any better in modern asp.net.
As long as you use regular HTML markup to define your UI and some Javascript to bring life to it, you should be fine.
Twitter's bootstrap is used for presentation and doesn't have to do anything with any programming language. You can use the bootstrap in any project using any language provided that you include the bootstrap.css stylesheet and use the CSS classes included accordingly, so there should be no concerns over whether the bootstrap will "transfer over to ASP" or any other language.
You can apply the Bootstrap CSS classes to ASP.NET controls using the CssClass parameter:
<asp:Button id="btnExample" runat="server" CssClass="btn btn-default" Text="Example" />
I would like to know what is the best practice on separating the content of an aspx page (ASP.NET 3.5) from the code (I'm using C#). I have a form that users can type data in - for example they are allowed to enter a percent. If they enter data that's not valid they would get an error message:
<p class="errormsg" id="percenthigh">Please enter a percent below 100</p>
<p class="errormsg" id="percentnegative">Percent cannot be below 0</p>
<p class="errormsg" id="percentnot">This is not a percent</p>
So in essence I'm hiding the error messages and showing one depending on what the user input is.
I believe this is the best way to seperate the content from the code behind. However, how do I select elements and hide/unhide them depending on the user input? I'm aware I can do a runat="server" on the elements but the problem is that I can't select by class and am limited only to ID's.
What workarounds do you recommend? Aside from putting in the values in code behind which is notoriously difficult to debug.
Also has this been "fixed" in ASP.NET 4? And I'm interested in doing this only via C#/ASP.NET as some people have JavaScript disabled. This means that I would have to check errors on both client side and server side.
Use an ASP.Net Validation control for this. That will take care of the wiring in the code for you. You use a different Validation control for each of the paragraph tags in your question.
You should take a look to asp net validators. In most of the cases these are good enough.
If ASP NET validators are not suitable for any reason you could check a jQuery solution like this one
In any case, I'd recommend you to avoid spending time solving problems already solved in many different (good) ways.
Selectionm should be by ID when you want unique elements, ID should be unique across all of your elements. Class is used like a type in HTML, and is generally used for styling.
Also, text in asp.net projects should be saved in resource files. This allows easy changing of languages.
I realize this is probably a fundamental thing I should know but I am self-teaching myself C# and asp.net so I am a little lost at this point.
I right now have 2 pages. One is an .aspx (with aspx.cs file included) that is blank and html is generated for it from a Page_Load function in the cs file. The HTML is very simple and it is just an image and some text.
The second file is a shtml file which has lots of things, serverside includes, editable and noneditable areas. I want to put my webapp into this file. My asp.net app uses Response.Write to just write out the html. This does not flow well with this page as all that does is write it at the top of the page which is because it is ran first and generates it at the top.
How can I make it to where I can generate HTML code inside the page, like within a specific DIV so it does not mess up the page. Where would a starting point be in learning how to do that.
I should note that I do not need any interaction from the user. All of this should generate right away.
I think you need to read up on some basic ASP.Net documentation and tutorials. Response.Write is not the correct approach - you need to understand how the ASP.Net page lifecycle works and how WebControls are used to render the html.
ASP.Net tries to abstract away having to create your html manually for the most part.
So if i have understood the questions correctly.
You already have an existing page/application (the shtml file) that you want to extend with some new ASP.NET components by including output from the ASP.NET page in the existing page?
This is as not something that is out of the box "supported" by ASP.NET and you "won't" be able to execute the aspx page using SSI. But you can do the opposite, an ASP.NET page does support SSI. So if you are not using any other scripts in the shtml file this might be a solution.
Otherwise the only common solutions would be either to use an AJAX framework and let it call the ASP.NET from within the existing pages or to use an iframe solution. In both cases the client will be resposible for making the calls to the ASP.NET pages and merging the results.
And then you have a issue with controlling the output from the ASP.NET page?
The Polymorphic Podcast has a good article on Controlling HTML in ASP.NET WebForms .
You can add a Literal control to the page inside the div:
<div>
<asp:Literal ID="litMarkup" runat=server />
</div>
then in your code-behind:
litMarkup.Text = "<strong>Your markup</strong>";
I don't know how well this would work for you, but could you try using an iframe to house the ASP.NET page? This should keep it in the specified region and not overwriting your shtml file. It may be something to think about.
If it is necessary that you generate your HTML output from C# code, and you would use this in more than one place, I think you may be thinking of something like what are called ASP.NET Custom Controls (not to be confused with "User Controls"-- though you probably could put together a solution with those as well, using a Literal control as another person suggested). The MSDN documentation would be a good starting point. In general, though, the writing-out-HTML-yourself-from-code model (like you would with, say, CGI applications), is not the usual ASP.NET model of development, as it largely defeats the point of using ASP.NET at all. You'd mostly want to do this sort of thing if you are writing your own web control, though this might be exactly what you are doing (hard to tell from the description).
I'm writing a WinForms application that sends email messages (like a mail merge).
I'd like to use ASP.Net's rendering engine to render the HTML bodies of the messages.
What's the simplest way to get the rendered output of a single ASPX page without the entire ASP.Net runtime?
To make things harder, I'd prefer to compile the ASPX at runtime so that it can be modified without rebuilding the application. However, this is not a requirement; if it's too difficult, I'll give up on it.
Rick Strahl posted an article how to do this at this location: http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp. I know there is a way to call some internal .NET Framework methods but I can't remember what they are off hand.
You may want to consider using a templating lib like NVelocity. Using the WebForms rendering engine in this manner is a bit overkill and hackish at best.
As an aside: keep in mind that HTML in email sucks. Even the most elementary of CSS is ignored by the majority of email clients. If you want my advice, KISS and save your sanity: if you're going to automate emails, send only plain text.
I am a ASP.NET 3.5 web developer using VS 2008. I just started at a new company and there are alot of Web Designers here (never worked with Web Designers before). They all use Dreamweaver CS3 and PhotoShop (something i know nothing about).
What I would like to know is the following:
Would they have problems opening my ASP.NET pages in Dreamweaver? ( I heard they might not be able to ).
What about when i use MasterPages? Will they be able to open my pages when i use MasterPages, or must i stay away from MasterPages?
Thanks in advance!
They will be able to work with the markup in your aspx pages, as long as you aern't using complex server controls. Keep the markup fairly simple and you'll be OK. With master pages, they should be able to handle the layout stuff they need, and leave you to worry about the content areas. If you have the opportunity, try to go down a MVC route, this way you are encouraged to keep the code and the markup separate, and the designers will have an easy time seeing your aspx and ascx markup. Designers aren't evil, just different :)