ASP.NET - Stylish submit buttons

Sep 21, 2009 Posted by Lara Kannan 0 comments
Most people would agree the default look of submit buttons is rather dull and unattractive. Using CSS and a nice gradient background image, it's easy to transform a form button from a duck to a swan.

Demo:

<style type="text/css">
.formbutton{
cursor:pointer;
border:outset 1px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 1px 2px;
background:url(formbg.gif) repeat-x left top;
}
</style>

The image used:


<form>
<input type="text" style="width: 200px; border: 1px solid gray" />
<input type="submit" class="formbutton" value="Submit" />
</form>
I hope this ll help you. A 'Thank You' would be nice!

Share
Labels:

ASP.NET : Dynamically change a style at Run-Time

Posted by Lara Kannan 0 comments
A nice feature of CSS is the ability to assign multiple classes to can DOM element via the class attribute. This opens up the possibility to dynamically set a class assignment based on some logic as the page is being rendered.

The example below demonstrates having a common style rule and a rule added at run-time. Of course you are not limited to this methodology, there are many ways to apply styles to an element.
<div class="contentBox bkg1">...</div>
I find the solution from Chris blog, for easiest way to set something like a dynamic style at run-time is to define a public method in the page class to return the desired rule. For my demonstration I will return a style rule name based on a QueryString parameter, but you can use all sorts of criteria. I also chose to apply the rule to the Body tag.

This is a simple method to return a style rule to define the background color of the page. I have three rules defined.
public string GetBackgroundClass()
{
switch ( Request.QueryString["bkg"])
{
case "1":
return "bkg1";
case "2":
return "bkg2";
case "3":
return "bkg3";
default:
return "bkg1";
}
}
The style rules just set the color as follows, a nice egg shell (at least that is what I call it), red and blue.
.bkg1
{
background-color: #FFFFCC;
}

.bkg2
{
background-color: #C30000;
}

.bkg3
{
background-color: #0000CC;
}
Finally I just inline the call to the method in the HTML markup:
<body class="<%=GetBackgroundClass() %>">
I hope this ll help you. A 'Thank You' would be nice!

Share
Labels: ,

Split camelCase string in C#

Sep 10, 2009 Posted by Lara Kannan 0 comments
Recently in our project there was a requirement were in the validation of the large number text boxes were required to be done.

We were following the camel casing as a naming convection for the text box. Mention below function was used to break the camel case and show the appropriate message to the user.

You require passing the camel case string to the function SplitCamelCase and it will return the necessary string.

public string SplitCamelCase(string CamelCaseString)
{
return System.Text.RegularExpressions.Regex.Replace(CamelCaseString,
"([A-Z])",
" $1",
System.Text.RegularExpressions.RegexOptions.Compiled
).Trim();
}

Hope this helps.
Share
Labels:

Auto click a button in asp.net on page load event

Sep 5, 2009 Posted by Lara Kannan 0 comments
In page load event itself, you just call the that button click event.

private void Page_Load(object sender, System.EventArgs e)
{
Button1_Click(null, null); // This button event ll fire while page load.
}

This code will execute the button click event also, when page load event executes.
Share
Labels: ,