how to use the local resource file with code behind page? - c#

I want to make message strings independent of aspx file and code behind page
I want to know how to use the resource files with code behind to achieve this?
or is there any other way to do this, other than using resource files?

In software, there is always more then one way. ;)
But if you want to separate string literals from an aspx page, resource (resx) files are the accepted standard.
This article might help you get rolling.

Related

Transclude content of one ASPX page to another

Background: I'm trying to make an extremely light news sort of...thing that relies entirely on hard code ASPX documents (not my decision). What I would like to do is create a bit of dynamic updating by having the main news page pull the latest ASPX file from a folder and get its "TopContent" section on the main page. How would I best be able to do that? I'm stuck with ASP.NET 2.0 on this project as well.
So I didn't quite transclude ASPX documents, but I found a way to get this to work by having XML files with the data pieces I needed and just using that. No problem.
In detailed: An XML file containing the title, the top content and the main content and then using a URL argument to figure out which file to open.

Can people find and download the Code File linked to your aspx page?

So I imported this aspx page done by a former dev who worked for the company I'm in now. I found that the aspx page left by him doesn't have a codebehind file so I assumed this wasn't the source code. I can't find the source so I added a code file and try to work it out on my own. But my main concern is this: clients can't access the code behind, right? Is a manually added code file subject to the same protection?
The codebehind file is there as a place to put your server side code. However it's technically not necessary to have one since you can put the code in the aspx file using c# script tags. It's however recommended to put it in the codebehind file for better separation between markup and code.
It does not matter if you add it yourself or if Visual Studio adds it for you. It does not change anything in terms of access. In all events it executes on the server.
If your server is properly configured to run ASP.NET applications - which I believe it is - then IIS will not serve .cs files to a client. These will normally be accessible only through FTP. Try it yourself, by browsing to any .cs file in your application :)
Also notice that what you get when you browse to an .aspx file is not the very same code you'd see in Visual Studio, but the result of that being processed. IIS will serve the resulting HTML. So even if you have server side code in the ASPX file, that won't be visible to an end user browsing through your application.
Sounds like a web application project; in this case, the code is in the code-behind file as #TGH mentioned, and the code would be in the DLL compiled for the web application. Therefore, the only way to get that code is use a tool like Telerik JustDecompile, and decompile that DLL to grab the source code for EVERY file in the project. It would be much better to have the source, as these decompile tools do not include everything in that code-behind file.

No access to cooresponding .cs file in asp.net

The aspx page that I need to add code to has an aspx.cs file which was written by a company that has this aspx.cs file on their system (per contract) and I cannot modify/access.
Example: MyFile.aspx and no access file MyFile.aspx.cs
I need to use a label.text from the page in the control pages and also depending on IF ELSEIF statements it will call which of the different controls that it needs to execute.
What is a good way to do this when one does not have access to the aspx.cs file?
I have spent a couple days trying to find/figure out answers to this problem and keep running into problems.
You do have a strange situation here ;)
Here's one wild idea. You can change the Inherits attribute at the top of the .aspx file to substitue your own class instead.
Of course that means you have to rewrite all the logic behind the page -- or you can try to have your own class inherit the original one, but depending on visibility of original code this may not work.
Another option could be to use a decompiler to re-create all the source code of the web project from the compiled dll. But you may not be legally allowed to do that -- although I would point out that if you don't have the rights to use the code, you probably don't have the rights to use the .aspx either, even if you have access to them.

Subversion best practices, ASP.NET C# Site WebForm

I have one question about how to handle a webform sites, i have many sites sharing aspx.cs codes but the only diference is the aspx and the .css and images ones, how to handle this it with svn its driving me crazy.
Hi you're question isn't totally clear, but it sounds like maybe you should be using svn externals to share the .aspx.cs (code behind) files.
You can specify the different .css files in the distinct .aspx file markup.
Using svn externals will enable you to share the code behind.
Alternatively you could explicitly specify the code behind file in your aspx markup if you only wanted to have one physical .aspx.cs file.
Im tring to use a structure with codebehind, its apers to be the best one.

Can a non-embedded resource js file access resource file (.resx)?

I have used the embedded resource js file to reference the .resx file before.
(by including something like
[assembly: ScriptResource("Applications.Webs.Scripts.HelpModule.js",
"Applications.Webs.Scripts.Resources.HelpResources", "Resource.HelpResources")]
in the code behind of the page, where HelpModule.js is a embedded resource)
I was wondering if I can access the .resx when the js is a content file? I have heard "no"s so far. Does any one know if this can be done?
Thanks for your replies in advance.
If your question is whether you can use values from the .resx in the JavaScript code, the answer is "not directly". You'll have to expose the resources from the resx as JavaScript variables that are emitted with your response and parsed by the browser in order to use them in your JS.
You could fudge this a little
Use a HttpModule to parse the JS just before its sent down to the client
looking for 'Tags'.
When you encounter your Tag then replace it with the required value from the resx file...
I used a technique similar to this for localizing JS files recently...
Alternatively, you might be able to use AJAX to muddy it up a bit. If you built a small method that was designed to dip into the resx file you could asynchronously dip. If you didn't want to use all of the Microsoft AJAX compiled stuff (for whatever reason), you could use a small AJAX engine (they're everywhere) and just wire it up to a .ashx handler. That way you could dip into the compiled .resx anytime you needed to. You'd just have to be willing to accept whatever connection latency AJAX might give you.

Categories