Showing posts with label CSS. Show all posts
Showing posts with label CSS. Show all posts

Wednesday, September 15, 2010

How to register User Control specific CSS and Java Scripts

It is always optimistic to include usercontrol specific CSS and JS files only when the UserControl renders it's contents.
CSS File:
#userControlWrapper { width:400pxheight:400pxborder:solid 1px #f00background-color:#aaa; }
h1.Big { font-size:40px; }
Markup:
<%@ Control Language="C#" 
            AutoEventWireup="true" 
            CodeBehind="WebUserControl.ascx.cs"  
            Inherits="ActiveTest.WebUserControl" %>
<div id="userControlWrapper">
    <h1 class="Big">User Control...</h1>
</div>

I have CSS and JS files in the root of my web projects. If you would like to put then in diffrent folders you should specify the correct path along with the root url. 
 
 Then you can use Literral control to register the css and the ClientScript to register the JS files.
namespace ActiveTest
{
    public partial class WebUserControl : UserControl
    {
        public string RootUrl
        {
            get
            {
                Uri requestUri = Context.Request.Url;
                HttpRequest request = Context.Request;
                string rootUrl = string.Format("{0}{1}{2}{3}{4}",
                    requestUri.Scheme,
                    Uri.SchemeDelimiter,
                    requestUri.Host,
                    requestUri.IsDefaultPort ? string.Empty : string.Format(":{0}", requestUri.Port),
                    request.ApplicationPath);
                return rootUrl.EndsWith("/") ? rootUrl : string.Format("{0}/", rootUrl);
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string styles = "<link href=\"{0}WebUserControl.css\" rel=\"stylesheet\" type=\"text/css\" />";
            this.Page.Header.Controls.Add(new Literal() { Text = string.Format(styles, this.RootUrl) });
            this.Page.ClientScript.RegisterClientScriptInclude(this.GetType().Name, string.Concat(this.RootUrl, "WebUserControl.js"));
        }
    }
}

Thursday, September 09, 2010

How to hide page elements while printing

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <style type="text/css" media="print">
        #topNavigation { display:none; }
        #footer { display:none; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="topNavigation">
            Top Navigation
        </div>
        <div id="content">
            Content
        </div>
        <div id="footer">
            Footer
        </div>
    </div>
    </form>
</body>
</html>

Thursday, June 17, 2010

How to create a popup dialogue without using AJAX or java scripts - Asp.net

Screenshots:

There are some occations that we need to create popup messages and dialogues without using JavaScripts. (AJAX or JQuery). This article demonstrates how to show a dialogue or a popup using CSS and Asp.net
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <style type="text/css">
        div.DialogueBackground 
        { 
            position:absolute; 
            width:100%; 
            height:100%; 
            top:0; 
            left:0; 
            background-color:#777; 
            opacity:0.5;
            filteralpha(opacity=50); 
            text-align:center; 
        }
        div.DialogueBackground div.Dialogue 
        {
            width:300px; 
            height:100px; 
            position:absolute; 
            left:50%; 
            top:50%; 
            margin-left:-150px; 
            margin-top:-50px; 
            border:solid 10px #aaa; 
            background-color:#fff; 
        }
    </style>
    <script runat="server">
        public void DialogueAccept(object sender, EventArgs e)
        {
            this.ShowHideDialogueInternal(false);
        }
        public void ShowHideDialogue(object sender, EventArgs e)
        {
            Button button = sender as Button;
            this.ShowHideDialogueInternal(button.CommandArgument.Equals("show"));
        }
        private void ShowHideDialogueInternal(bool state)
        {
            this.pnlDialogue.Visible = state;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Panel runat="server" ID="pnlDialogue" CssClass="DialogueBackground" Visible="false">
            <div class="Dialogue">
                <p>This is a dialogue</p>
                <div class="ButtonPanel">
                    <asp:Button 
                        runat="server" 
                        ID="btnOK" 
                        Text="OK" 
                        OnClick="DialogueAccept" />
                    <asp:Button 
                        runat="server" 
                        ID="btnCancel" 
                        Text="Cancel" 
                        OnClick="ShowHideDialogue" 
                        CommandArgument="hide" />
                </div>
            </div>
        </asp:Panel>
        <h1>Sample Dialogue using C# (without JavaScripts)</h1>
        <hr />
        <asp:Button 
            runat="server" 
            ID="btnShowDialogue" 
            Text="Show Dialogue" 
            OnClick="ShowHideDialogue" 
            CommandArgument="show" />
    </form>
</body>
</html>

This is a optional Section. 
If you need, you can implement this as a Web Control:
Dialogue Control:
public class Dialogue : Panel
{
    string style = @"
        <style type=""text/css"">
            div.DialogueBackground 
            { 
                position:absolute; 
                width:100%; 
                height:100%; 
                top:0; 
                left:0; 
                background-color:#777; 
                opacity:0.5;
                filter: alpha(opacity=50); 
                text-align:center; 
            }
            div.DialogueBackground div.Dialogue 
            {
                width:300px; 
                height:100px; 
                position:absolute; 
                left:50%; 
                top:50%; 
                margin-left:-150px; 
                margin-top:-50px; 
                border:solid 10px #aaa; 
                background-color:#fff; 
            }
        </style>
    ";
 
    public string Message { getset; }
    public event EventHandler Accept;
    public event EventHandler Cancel;
    public Dialogue()
    {
        this.Visible = false;
        this.Message = "Are you sure?";
        this.CssClass = "DialogueBackground";
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        this.CreateControlHeirarchy();
    }
    public void CreateControlHeirarchy()
    {
        Button btnOk = new Button() { ID = "btnOK", Text = "OK", ValidationGroup = this.ID };
        btnOk.Click += new EventHandler(DialogueAccept);
        this.Controls.Add(btnOk);
        Button btnCancel = new Button() { ID = "btnCancel", Text = "Cancel", ValidationGroup = this.ID };
        btnCancel.Click += new EventHandler(HideDialogue);
        this.Controls.Add(btnCancel);
    }
    private void DialogueAccept(object sender, EventArgs e)
    {
        this.Hide();
        if (this.Accept != nullthis.Accept(sender, e);
    }
    private void HideDialogue(object sender, EventArgs e)
    {
        this.Hide();
        if (this.Cancel != nullthis.Cancel(sender, e);
    }
    public void Show()
    {
        this.Visible = true;
    }
    public void Hide()
    {
        this.Visible = false;
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        if (this.Page != null && this.Page.Header!=null)
            this.Page.Header.Controls.Add(new Literal() { Text = this.style });
    }
    protected override void RenderContents(HtmlTextWriter writer)
    {
        writer.Write("<div class=\"Dialogue\">");
        writer.Write(string.Format("<p>{0}</p>"this.Message));
        writer.Write("<div class=\"ButtonPanel\">");
        base.RenderContents(writer);
        writer.Write("</div>");
        writer.Write("</div>");
    }
}

Page (how you can use the Dialogue control): 
<%@ Page Language="C#" CodeBehind="~/Test.aspx.cs" Inherits="ActiveTest.Test" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">   
 <script runat="server">      
     public void Save(object sender, EventArgs e)
        {
            this.dlgConfirm.Show();
        }
        public void Accept(object sender, EventArgs e)
        {
            ///
            /// Confirmed... we can save data here...
            /// 
        }
        public void Cancel(object sender, EventArgs e)
        {
            
        }   
 </script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
        <asp:Dialogue 
            runat="server" 
            ID="dlgConfirm" 
            Message="Are you want to save this details" 
            OnAccept="Accept" 
            OnCancel="Cancel" />
        <asp:Button runat="server" ID="btnSave" OnClick="Save" Text="Save" />
 </div>
 </form>
</body>
</html>

Wednesday, May 06, 2009

CSS Element selectors [pattern matching] - Cascade Style Sheet Syntax (CSS Syntax)

PatternMeaningDescribed in section
*Matches any element.Universal selector
EMatches any E element (i.e., an element of type E).Type selectors
E FMatches any F element that is a descendant of an E element.Descendant selectors
E > FMatches any F element that is a child of an element E.Child selectors
E:first-childMatches element E when E is the first child of its parent. The :first-child pseudo-class
E:link
E:visited
Matches element E if E is the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited). The link pseudo-classes
E:active
E:hover
E:focus
Matches E during certain user actions.The dynamic pseudo-classes
E:lang(c) Matches element of type E if it is in (human) language c (the document language specifies how language is determined).The :lang() pseudo-class
E + FMatches any F element immediately preceded by a sibling element E.Adjacent selectors
E[foo]Matches any E element with the "foo" attribute set (whatever the value).Attribute selectors
E[foo="warning"]Matches any E element whose "foo" attribute value is exactly equal to "warning".Attribute selectors
E[foo~="warning"]Matches any E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "warning".Attribute selectors
E[lang|="en"]Matches any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en".Attribute selectors
DIV.warningLanguage specific. (In HTML, the same as DIV[class~="warning"].)Class selectors
E#myidMatches any E element with ID equal to "myid".ID selectors

Reference: W3C CSS Guidlines (Section 5: Selectors)

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...