I want to display a webpage in a WebBroswer in my winforms application. I however want to use some custom css to change how the page looks. Is it possible to attach a style sheet and edit the html page you are viewing?
You can use this web control http://www.codeproject.com/KB/miscctrl/csEXWB.aspx
and save it as a web page and load and you can show the source in another text box , once changes are made you can save to a temp file and load it. There is an option to view local file.
I don't think that kind of thing is supported.. but anyway that would be a horrible thing to do. you may end-up interfering with the CSS used by the client page.
Have you ever seen your browser override your CSS used by page and say i want to show it this way. (I know development tools like firebug,etc do it)
Related
I´m wondering if it could be possible to change the HTML document text directly from the web Browser.
I´m currently working on an email client, which uses a html template for the design.
Everything seems good but I need to configure the template.
Like I said, the template is stored in a rich textbox, which is invisible.
Basically I can see the web Browser with its template, only.
Now I want to insert my custom text to the template.
Is it possible to change the htmldocumenttext directly from the webbrowser ?
Is there another way to edit the content of the template ?
You bet it's possible. Whole libraries are written around modifying the HTML after initial delivery to the browser. Start here: http://www.w3schools.com/js/js_htmldom.asp. Then maybe: https://jquery.com/
I've got a aspx and aspx.cs file with some components. Now I want to reuse parts of that page in another page. My approach would be to pull out the duplicate part into a WebServerControl.
So before I waste more time yahoogling, is that even the right idea and if so, is there a way to use parts of the aspx file rather than doing it tediously in RenderContents with the HtmlTextWriter, WriteBeginTag, WriteAttribute and so on. That looks like a mess for complicated layout and sizeable amounts of controls.
What's the standard?
Depends.
The main driving factor is that if you need to reuse your control in multiple web applications, you should go with a Custom Control (.cs in C#).
Else, if you only intend to reuse your control in one web application, choose a User Control (.ascx).
This MSDN article is a good starting point.
UPDATE (since OP asked further details):
To embed JavaScript for a custom control, a common approach is
var initializeScript = string.Format("MyNamespace.initialize('{0}', {1});", ClientID, myScriptString);
Attributes.Add("onmouseover", initializeScript);
Suggest to write JavaScript code in a js file and not in .cs since the latter is a nightmare to maintain and debug. Hope this helps.
It sounds like what you want to do is bundle the items into a User Control. This will allow you to design the control by using existing .NET controls rather than rendering everything out from scratch.
All you need is to create an ASP.NET Web User Control
Taken from MSDN:
An ASP.NET Web user control is similar to a complete ASP.NET Web page
(.aspx file), with both a user interface page and code. You create the
user control in much the same way you create an ASP.NET page and then
add the markup and child controls that you need. A user control can
include code to manipulate its contents like a page can, including
performing tasks such as data binding.
I am working with a C# on visual studios.
What I would like to know is if it is possible to have a html template loaded from a directory on my computer. Then every time I load up my code it will load up the .html template automatically.
Yes there is a way, not suggested but exist. You can use this code to include the file, inside your asp.net page.
<!--#include file="template.htm"-->
What is dose is that is load this htm file and show it on the place that you have place this declaration. Also you must know that this file can not contain anything dynamically. This is a command code that comes from the old asp script code, and still work on asp.net
So I can not call it as template. If you wish to make something like a real template you must use a master page. Using a master page is far better, and you just copy paste your htm code inside the master page and there you have it.
relative: http://triaslama.wordpress.com/2008/11/19/how-to-include-file-in-aspnet-pages/
I'm using WebBrowser control in .NET app. I construct a html text, then set the controls property DocumentText to this html. It works fine on my computer. On some other computers it simply displays the source as a text. I think that it may be connected with some explorer properties but I don't really know why it is behaving like this. How can I handle it to always display proper view? Or at least what can I fix on a specific computer so that the application works fine/
There is allways the sucky way of dumping the HTML to disk and set the URL to the file. But that is not a good solution.
I have created a webpart in c# for sharepoint.
its basically a form with text boxes, literals, validators and buttons.
im not sure how to render this form to make it look pretty.
The layout etc is being done entirely within this c# class.
At the moment to get started im just overrinding CreateChildControls() method
and adding each form control using something like: this.Controls.Add(submitButton);
any ideas on how best to layout this form?
Thanks.
When creating custom webparts I also prefer to implement them by overriding the CreateChildControls() and Render() methods. In the Render() method I have full control of the html output and I can render my inner controls by calling this.someInnerControl.RenderControl(writer).
Having full control of the html output also makes it easy to style the html using CSS. As other people suggests, use an external CSS file and apply the styes to the class attribute on html elements or CssClass property on ASP.NET web control.
When I implement webparts, that does not require special branding, I prefer to reuse the CSS classes defined by SharePoint. This will ensure that my webpart is visually similar to the webpart provided by SharePoint and that I keep a consistent look and feel.
When using the SharePoint defined CSS styles, you should be aware of your html output. Some of the CSS classes requires a specific html structure to properly render. You can always use the browsers "View Source" to check the html of the SharePoint element you are trying to imitate.
I would recommend grabbing the source from an existing sharepoint page and using the styles defined by sharepoint. This link to the styles in 2003 is old, but still a good guide to get started. Most of the CSS class names haven't changed.
In my web parts I include css files in the solution and inject them in the page using something like:
this.Page.Header.RegisterCss("/_layouts/path/to/css/file.css", false);
You can override the RenderContents(...) method to manually render the HTML in anyway you want to. This includes adding any css includes, scripting includes, etc. that you want/use.
You can render your child controls to strings and then output them as well, but you probably should NOT call the base.RenderContents(...) method.
Just make sure you don't forget to render your child controls.
If it's important for you to see as you design, use the SmartPart which embeds a user control in a web part. (In case you didn't know, user controls can be designed using the tools within Visual Studio.)
If you prefer to hand-code, then you're on the right track. Simply create and set initial properties for your controls within the CreateChildControls() method and use this.Controls.Add() as you have been.
In both cases, where possible use the CssClass property so you can tinker with the look and feel in a CSS file without having to recompile. You could hard-code the CSS class names but it would be better to use the web part properties or an external config source to store these. Have a reference to the CSS file in your master page or inject it into the page using the other techniques mentioned in this answer.
The MSDN articles Web Parts in Windows SharePoint Services or Creating a Basic Web Part might also help.