【发布时间】:2011-01-26 01:40:05
【问题描述】:
我是本科生。我有一些与在 ASP.NET 服务器端自定义控件中嵌入 jQuery 相关的查询。
私有字符串 GetEmbeddedTextFile(string sTextFile) { // 检索内容的通用函数 // 嵌入文本文件资源的字符串
// we'll get the executing assembly, and derive
// the namespace using the first type in the assembly
Assembly a = Assembly.GetExecutingAssembly();
String sNamespace = a.GetTypes()[0].Namespace;
// with the assembly and namespace, we'll get the
// embedded resource as a stream
Stream s = a.GetManifestResourceStream(
string.Format("{0}.{1}",a.GetName().Name, sTextFile)
);
// read the contents of the stream into a string
StreamReader sr = new StreamReader(s);
String sContents = sr.ReadToEnd();
sr.Close();
s.Close();
return sContents;
}
private void RegisterJavascriptFromResource()
{
// load the embedded text file "javascript.txt"
// and register its contents as client-side script
string sScript = GetEmbeddedTextFile("JScript.txt");
this.Page.RegisterClientScriptBlock("PleaseWaitButtonScript", sScript);
}
private void RegisterJQueryFromResource()
{
// load the embedded text file "javascript.txt"
// and register its contents as client-side script
string sScript = GetEmbeddedTextFile("jquery-1.4.1.min.txt");
this.Page.ClientScript.RegisterClientScriptBlock(typeof(string), "jQuery", sScript);
// this.Page.RegisterClientScriptBlock("JQueryResourceFile", sScript);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// the client-side javascript code is kept
// in an embedded resource; load the script
// and register it with the page.
RegisterJQueryFromResource();
RegisterJavascriptFromResource();
}
但我面临的问题是,我在单独的 .JS 文件中编写并尝试嵌入自定义控件的所有 JQuery 代码都在屏幕上作为输出流式传输。另外,我的控件没有正常运行,由于没有正确嵌入,jQuery 功能无法正常工作:-( 请帮帮我! 谢谢!
【问题讨论】:
标签: asp.net jquery streaming custom-controls embed