Click here to Skip to main content
15,920,688 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a block of CSS I'm trying to inject into a webbrowser control. I'd do the SetAttribute("src", "filename.css"), but the web page is on https and I get a stupid security exception popping up each time.

So I tried via createElement("style"), but I can find no way of adding the
CSS
.autocomplete {
    font-family: Tahoma;
    font-size: 8pt;
    background-color: white;
    border: 1px solid black;
    position: absolute;
    cursor: default;
    overflow: auto;
    overflow-x: hidden;
}
.autocomplete_item {
    padding: 1px;
    padding-left: 5px;
    color: black;
    width: 100%;
}
.autocomplete_item_highlighted {
    padding: 1px;
    padding-left: 5px;
    color: white;
    background-color: #0A246A;
}


to the element so it can be appended to the head element. The error thrown when I try InnerText or InnerHTML is "This property is not supported". This maybe a case of I'm using the wrong search words again, but can't seem to find a solution to this.
Posted

1 solution

I would recommend moving this out to its own .css file. From there you should be able to use a literal control as such:

<asp:Literal ID="cssInjector" runat="server" Mode="PassThrough" Text="<link rel='stylesheet' type='text/css' media='all' href='/YourCssFileReference.css' />"></asp:Literal>

By specifying the mode as passthrough the literal control acts as an injection point and will pass its text field straight inline.

This should work for you but I can't verify that SSL won't mess it up
 
Share this answer
 
Comments
Franklin Smith 19-Mar-11 17:46pm    
This will not work, this is being done in webbrowser control not on a aspx page. It has to be manually inserted after the page loads. I also have javascript that has to be inserted to operate the autocomplete on a text box that will speed up data entry. If I was going to do it as a file I would just create a link instead and set the src and appropriate type.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900