当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net ajax - Adding an ScriptReference Dynamically which is a page request to ScriptManager

问题描述:

I use ScriptManager in my ASP.NET page, and want to add a ScriptReference which is a page request like this:

var id = 10;

tsm.CompositeScript.Scripts.Add(new ScriptReference("~/Response.aspx?action=test&id=" + id));

but it raises an error:

'~/Response.aspx?action=test&id=10' is not a valid virtual path.

I should add this script dynamically, what should I do?

网友答案:

You're trying to mix a virtual path with querystring parameters, I think the underlying ASP.NET method that resolves the "~" part expects the string to be a pure virtual path, not a url. So map it as a pure path first, then add the query:

tsm.CompositeScript.Scripts.Add(new ScriptReference(ResolveClientUrl("~/Response.aspx") + "?action=test&id=" + id));

分享给朋友:
您可能感兴趣的文章:
随机阅读: