asp.net - Code shortening in aspx page -


( i'm not native english speaker, text may not natural )

i'm doing localization of asp.net project. efficiency of language translation, i'm extracting strings in .aspx global resource file. ( named resource file 'stringtable.resx'. )

in process, strings in aspx page changes follows :

before : admin id

after : <asp:literal runat="server" text="<%$ resources:stringtable, str_admin_id %>">

the 'after code' looks little bit long, want shorten code. ( example, remove runat="server" statement, remove resource name, etc... ) in c/c++ case, 1 can use #define macro.

is there way in .aspx page? ( not in code behind file ) idea appreciated.



====== below own answer ========================================

i'm using vs2008, can't use <%: syntax in .net 4.0.

and introduce alternative solution ( i'm not sure best solution )


first, added directive in upper portion of .aspx file.

<%@ import namespace="resources" %> 

( wanted set namespace="resources.stringtable" remove repetitive 'stringtable', not allowed. )

and after that, replaced

<asp:literal runat="server" text="<%$ resources:stringtable, str_admin_id %>"> 

to

<%= stringtable.str_admin_id %> 



it's not clean in keyword 'stringtable' still exist, looks better original code. :)



====== add ========================================

but when using method, 'design' preview mode of visual studio doesn't show resource string..

so seems have return original long code. :(

( method works 'design' mode 'refresh' function. )

<%: stringtable.str_admin_id %> 

...is need :)

this uses new <%: snyntax introduced in asp.net 4, if you're using 2 or 3 you'll need <%= html.encode( (mvc) or <%= server.htmlencode (webforms)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -