I have a Blazor component, which I want not to be afected by the General Styles of the projects that use it.
The main problem is that the project that implements this Component, overrides some of the styles in their general styles.css, and it breaks the layout (principally because their project overrides some Bootstrap names).
I have been searching and found the CSS property all:revert; that I could add it to the first line of my component styles like this:
* {
all:revert;
}
So all the previous code that was modifying the component won't affect it.
But I'm not sure if this is the best solution to this problem.
Any help is appreciated.
Related
I've made a simple glade UI file for my programm. It contains of 2 textfields and 1 button. And also I made a css style which contains 1 button class named "button". When I added this file in Glade as "Custom CSS provider" it changed my button style within the editor.
After that I created the UI using GtkBuilder (I am using GTK# 3.20 bindings + C#).
Builder b = new Builder ();
b.AddFromFile ("login.xml");
b.Autoconnect (this);
It created my simple form (2 fields and 1 button) but there is no CSS Style applied to it. So I checked XML code of my UI file and found out that there is no reference to CSS exept of this:
<style>
<class name="button"/>
</style>
After that I read that I need CssProvider. So I created one.
CssProvider css = new CssProvider ();
css.LoadFromPath ("ui_common.css");
But nothing happened. So, how should I apply custom CSS to my Builder UI?
You are almost there; the last step is to take the GtkCssProvider and add it to a GtkStyleContext.
Since you are using a .ui file and a .css file, I assume you want to make your CSS apply to all widgets in the application. In that case, you can use gtk_style_context_add_provider_for_screen(), passing gdk_screen_get_default() as the GdkScreen. (This should be safe; it's what the GTK+ Inspector does. IIRC there was a more specific reason why this should be safe...)
You can also do this to individual widgets using gtk_widget_get_style_context() and gtk_style_context_add_provider().
In both cases, use GTK_STYLE_PROVIDER_PRIORITY_APPLICATION as the priority for application-local CSS.
(I do not know the C# names; sorry.)
I created a child template from visual studio to manage my kentico template. The template worked fine except that all the controls in it is not accessible from code behind because it is not recognized. I have checked for on line solution but none solved the issue. I even got this link
Codebehind file doesn't recognize aspx-controls
without any luck since I can't even access the myfile.aspx.designer.cs.
What do I trie again?
Note: My controls are not inside any panel or other control. Just inside a normal div.
Try adding runat="server" to your id tag.
Here is an example.
<tr class="headerrow" id="tbrHeader" runat="server">
I am unfamiliar with Kentico, but this is what I have come up with as possible solutions without having seen your code:
Make sure all your controls have a 'runat' attribute: runat="server". I am not trying to insult your intelligence, but it is an easy thing to forget(As I have done before), without this the control won't be recognised from code-behind
If it is a template file, have you made sure the codebehind that refers to it, is the code-behind of the template file, as the codebehind of other pages will not be able to find the control in the template without you telling them where it is.
With your new comment on the question: If your class is abstract, have you tried wrapping it in a non-abstract class? (source: stackoverflow.com/questions/481305)
I am decision dilemma as to the requirement of a client
I want to change the look and Layout both of the site - XXX Client
Generally this is how it should work,
You change a theme the website is displayed with different images and Colors.
You change a masterpage your website changes it's layout (sidebar moved to right from left - provided the layout is specified in masterpage)
I am confused as to how one would accomplish this. If i design my pages using a default masterpage then when i switch to another masterpage there is no assurance that other masterpage might have same content placeholders.
This would throw an exception
How can i implement multiple masterpages Intelligently without creating 2 pages each for the respective masterpage ?
Edit
dilemma is caused by other colleague implementing his own ideas into pages developed by him, He over popups to display forms on sidebar link clicks mine directs to separate pages.
You should be able to achieve this in CSS without changes to masterpages or themes. That way you will guarantee that the content placeholders will be unchanged.
Change your images to be set from CSS (something like):
.imageFromCss { background:url("../images/myimage.png");}
And CSS can move sidebars from left to right:
.sidebar {display:inline; float:right;}
You can change dynamicly the masterpage on PreIint.
Select Case iForum
Case 6 '41
MasterPageFile = "/Children/Forum.master"
Case Else
MasterPageFile = "/Ezra/Forum.master"
End Select
(I know that I can write better example)
Now, Create a BaseMaster class, with your variables, functions, etc, and inherit the website MasterPage from this class.
Now add to the top of page:
<%# MasterType TypeName="ForumMaster"%>
And now just use Master.YourFunction(). It will work with all MasterPages.
Good Luck !
I'm creating a SharePoint web part in C# that is using an UpdatePanel for some AJAX magic. Everything is working fine, but I'd like to know how to lay out my controls visually (without using SharePoint Designer). I just have two dropdownlists, some labels, a button, and a textbox. I am creating them within the overridden CreateChildControls. Thanks!
add a container panel around your controls and give it a class. Add the panel to the UpdatePanel's container. Add all other controls to the new Panel's Controls.
You can now use css to do your styling, using the container panel's CssClass as reference.
in code:
protected override CreateChildControls()
{
// .. creation of updatepanel, say upd1
Panel container = new Panel{CssClass = "webpartContainer"};
upd1.ContentTemplateContainer.Controls.Add(container);
container.Controls.Add(dropdown1); // etc. etc.
}
The Css:
.webpartContainer
{
/* if needed add some style here also */
}
.webpartContainer select
{
/* add style */
}
.webpartContainer .specificClass
{
/* give controls a class of their own in CreateChildControls
if controls of the same type need different styling
(i.e. you have more than 1 select that need to look different) */
}
there are a couple of ways you can lay them out. you can add a Table object and add rows, cells, etc. and add your controls to the cells.
Alternately, you can override the RenderContents method and output HTML directly to the write that is passed in as a parameter. If you do this method (its probably less work and more efficient then using the Table objects), you should use a StringBuilder to build your HTML then output the results to the writer. This method should gain you some performance.
Sadly, there is no visual WYSIWIG editor for this method.
Unfortunately, there is no visual designer for web parts that are created programmatically.
You can use a user control and the SmartPart web part from codeplex to gain advantage of the visual designer for .ascx user controls.
You can use ASCX files in web parts.. just load it from your webpart class in CreateChildControls like so:
var control = Page.LoadControl("/_CONTROLTEMPLATES/yourproject/your.ascx");
Controls.Add(control);
This way you can use the normal way with Visual Studio to layout your webpart. Much nicer than building HTML in code which is a pain to say the least.
(this is also much better than using SmartPart which causes issues with the trustlevel and deployment)
Summary
Hi All,
OK, further into my adventures with custom controls...
In summary, here is that I have learned of three main "classes" of custom controls. Please feel free to correct me if any of this is wrong!
UserControls - Which inherit from UserControl and are contained within an ASCX file. These are pretty limited in what they can do, but are a quick and light way to get some UI commonality with designer support.
Custom Composite Controls - These are controls that inherit from WebControl where you add pre-existing controls to the control within the CreateChildControls method. This provides great flexibility, but lack of designer support without additional coding. They are highly portable though since they can be compiled into a DLL.
Custom Rendered Controls - Similar to Custom Composite Controls, these are added to a Web Control Library project. The rendering of the control is completely controlled by the programmer by overriding the Render method.
My Thoughts..
OK, so while playing with custom composites, I found the following:
You have little/no control over the HTML output making it difficult to "debug".
The CreateChildControls (and subsequent methods) can get real busy with Controls.Add(myControl) everywhere.
I found rendering tables (be it for layout or content) to be considerably awkward.
The Question(s)..
So, I admit, I am new to this so I could be way off-base with some of my points noted above..
Do you use Composites?
Do you have any neat tricks to control the HTML output?
Do you just say "to hell with it" and go ahead and create a custom rendered control?
Its something I am keen to get really firm in my mind since I know how much good control development can cut overall development time.
I look forward to your answers ^_^
I say go ahead with the custom rendered control. I find that in most cases the composite can be easier done and used in a UserControl, but anything beyond that and you'd need to have a finer degree of control (pun unintended) to merit your own rendering strategy.
There maybe controls that are simple enough to merit a composite (e.g., a textbox combined with a javascript/dhtml based datepicker, for example) but beyond that one example, it looks like custom rendered controls are the way to go.
Here's another extension method that I use for custom rendering:
public static void WriteControls
(this HtmlTextWriter o, string format, params object[] args)
{
const string delimiter = "<2E01A260-BD39-47d0-8C5E-0DF814FDF9DC>";
var controls = new Dictionary<string,Control>();
for(int i =0; i < args.Length; ++i)
{
var c = args[i] as Control;
if (c==null) continue;
var guid = Guid.NewGuid().ToString();
controls[guid] = c;
args[i] = delimiter+guid+delimiter;
}
var _strings = string.Format(format, args)
.Split(new string[]{delimiter},
StringSplitOptions.None);
foreach(var s in _strings)
{
if (controls.ContainsKey(s))
controls[s].RenderControl(o);
else
o.Write(s);
}
}
Then, to render a custom composite in the RenderContents() method I write this:
protected override void RenderContents(HtmlTextWriter o)
{
o.WriteControls
(#"<table>
<tr>
<td>{0}</td>
<td>{1}</td>
</tr>
</table>"
,Text
,control1);
}
Rob, you are right. The approach I mentioned is kind of a hybrid. The advantage of having ascx files around is that on every project I've seen, designers would feel most comfortable with editing actual markup and with the ascx you and a designer can work separately. If you don't plan on actual CSS/markup/design changes on the controls themselves later, you can go with a custom rendered control. As I said, my approach is only relevant for more complicated scenarios (and these are probably where you need a designer :))
I often use composite controls. Instead of overriding Render or RenderContents, just assign each Control a CssClass and use stylesheets. For multiple Controls.Add, I use an extension method:
//Controls.Add(c1, c2, c3)
static void Add(this ControlCollection coll, params Control[] controls)
{ foreach(Control control in controls) coll.Add(control);
}
For quick and dirty rendering, I use something like this:
writer.Render(#"<table>
<tr><td>{0}</td></tr>
<tr>
<td>", Text);
control1.RenderControl(writer);
writer.Render("</td></tr></table>");
For initializing control properties, I use property initializer syntax:
childControl = new Control { ID="Foo"
, CssClass="class1"
, CausesValidation=true;
};
Using custom composite controls has a point in a situation where you have a large web application and want to reuse large chunks in many places. Then you would only add child controls of the ones you are developing instead of repeating yourself.
On a large project I've worked recently what we did is the following:
Every composite control has a container. Used as a wrapped for everything inside the control.
Every composite control has a template. An ascx file (without the <%Control%> directive) which only contains the markup for the template.
The container (being a control in itself) is initialized from the template.
The container exposes properties for all other controls in the template.
You only use this.Controls.Add([the_container]) in your composite control.
In fact you need a base class that would take care of initializing a container with the specified template and also throw exceptions when a control is not found in the template. Of course this is likely to be an overkill in a small application. If you don't have reused code and markup and only want to write simple controls, you're better off using User Controls.
You might be able to make use of this technique to make design-time easier:
http://aspadvice.com/blogs/ssmith/archive/2007/10/19/Render-User-Control-as-String-Template.aspx
Basically you create an instance of a user control at runtime using the LoadControl method, then hand it a statebag of some kind, then attach it to the control tree. So your composite control would actually function like more of a controller, and the .ascx file would be like a view.
This would save you the trouble of having to instantiate the entire control tree and style the control in C#!