Thanks for Nathan's good suggestions.
Hi Alex,
I think Nathan's suggestion on creating some script template files and load
script fragment from them at runtime is a good idea. Also, more
specifically, you can consider the following means:
1). create a separate class library project
2) create some script template files(text files) which contains the scritp
functions/template functions and compiled them as "embeded resources" in
that class library project.
3). Reference that class library in your ASP.NET web application so that
you can dynamically load the script/template files as resource stream from
the class library assembly. e.g.
===============
protected void Page_Load(object sender, EventArgs e)
{
Stream stream =
typeof(WSProxyLib.Class1).Assembly.GetManifestReso urceStream("WSProxyLib.scr
ipttemplate.txt");
StreamReader sr = new StreamReader(stream);
string template = sr.ReadToEnd();
Response.Write("<br/>" + Server.HtmlEncode(template));
}
===============
Also, you can use the "WebResource" feature to link external files(css or
script files that embeded in .net assembly) in your asp.net page
#WebResource ASP.NET 2.0 explained
http://www.codeproject.com/aspnet/MyWebResourceProj.asp
In addition, if you do want to put the script functions in aspx template
and utilize the server control's "ClientID" property, you can consider
using the <%= % expression to embed ClientID into script. e.g.
================
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" >
function testfunc()
{
var id = "<%= Button1.ClientID %>";
var elm = document.getElementById( id );
alert(elm.value);
}
</script>
</head>
================
You can tried this in your aspx page if there is just some simple script
snippets. However, we still recommend that you consider using a template
file and load it at runtime because embed <%= %will make the code logic
mixed with UI template in aspx which is not good practice generaly.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial
response from the community or a Microsoft Support Engineer within 1
business day is
acceptable. Please note that each follow up response may take approximately
2 business days
as the support professional working with you may need further investigation
to reach the
most efficient resolution. The offering is not appropriate for situations
that require
urgent, real-time or phone-based interactions or complex project analysis
and dump analysis
issues. Issues of this nature are best handled working with a dedicated
Microsoft Support
Engineer by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.