ASP.NET PHP.NET CODEITWELL MASHABLE OPENSOURCEWEBDESIGN BLOGDUMPS FACEBOOK APPS

Home ASP.NET PHP WINDOW Web Programming Web Logic Web Design css Archives
Sunday, August 30

IButtonControl in ASP.NET. Do you know this? Just try and see.

0 comments

One nice feature of ASP.NET 2.0 is a new interface called IButtonControl.
You can use it in a code behind to say a control needs to be a button
but without actually saying whether it needs to be a Button,
LinkButton, ImageButton or custom control button type.


This is the type of thing that’s useful if you have a code behind
used by multiple different aspx pages, each with slightly different
requirements of what the button should look like. It also means you can
switch between the three without having to change the code behind.


So instead of a huge ugly if statement like this:


Button button = Page.FindControl("Button1") as Button;
ImageButton imageButton = Page.FindControl("ImageButton1") as ImageButton;
LinkButton linkButton = Page.FindControl("LinkButton1") as LinkButton;
if(button != null)
button.Text = "Click me";
else if(imageButton != null)
imageButton.Text = "Click me";
else if(linkButton != null)
linkButton.Text = "Click me";

Instead you can support all three scenarios nice and simply like this:


IButtonControl button = Page.FindControl("Button1") as IButtonControl;<br />button.Text = "Click me";<br />

Comments
0 comments
Do you have any suggestions? Add your comment. Please don't spam!
Subscribe to post feed

Your comments here...

Some Useful Books

http://books.google.com.np/books?id=Lan3g76cCFYC&lpg=PP1&dq=photoshop%20shortcuts&hl=en&pg=PT1#v=onepage&q=photoshop%20shortcuts&f=false

About Me

SubscribeSubscribe via RSS

SubscribeRecent Posts

SubscribeHot Links

Archive

Live Traffic Feed