Getting htc files from ressources in ASP.NET 2

W

WT

Hello,

Is it possible to get an htc file from a resource using
ClientScript.GetWebResourceUrl(rsType, htc_fileName);

et setting this value in the implementation attibute ?

It doesn't seems to work.

Thanks for help
 
W

Walter Wang [MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top