Hi,
Thank you for post!
It's possible to get an htc file from a resource using
ClientScript.GetWebResourceUrl(rsType, htc_filename), see following example.
Suppose we have a web control project has default namespace
'EmbeddedWebResourceControlsLib', and has an embedded resource file
'Htc1.htc' with following content:
---------------
<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="Hilite()" />
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="Restore()" />
<SCRIPT LANGUAGE="JScript">
var normalColor, normalSpacing;
function Hilite()
{
// save original values
normalColor = runtimeStyle.color;
normalSpacing= runtimeStyle.letterSpacing;
runtimeStyle.color = "red";
runtimeStyle.letterSpacing = 2;
}
function Restore()
{
// restore original values
runtimeStyle.color = normalColor;
runtimeStyle.letterSpacing = normalSpacing;
}
</SCRIPT>
</PUBLIC:COMPONENT>
---------------
And we register it in AssemblyInfo.cs:
---------------
[assembly: WebResource("EmbeddedWebResourceControlsLib.Htc1.htc",
"text/x-component")]
---------------
Then we can use following code in our control to call the behavior:
---------------
private void AddBehavior()
{
string includeTemplate = "<STYLE> LI {{behavior:url({0})}}</STYLE>";
string includeLocation =
Page.ClientScript.GetWebResourceUrl(this.GetType(),
"EmbeddedWebResourceControlsLib.Htc1.htc");
LiteralControl include = new
LiteralControl(String.Format(includeTemplate, includeLocation));
((System.Web.UI.HtmlControls.HtmlHead)Page.Header).Controls.Add(include);
}
protected override void OnPreRender(EventArgs e)
{
AddBehavior();
base.OnPreRender(e);
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write("<UI><LI>Hello</LI></UL>");
}
---------------
Hope this helps. If there's anything unclear, please feel free to post here.
Regards,
Walter Wang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.