Xerratus
Happily stressed out, since 1974
Wednesday, August 15, 2007
<< New furniture
Community Server: Unable to start debugging on the web server solution >>
Community Server: Create custom image button control that inherits CSLinkButton
Working on a project today that has some aspects that integrate with Community Server, I ran into a slight problem. I needed to replace the submit resource link button for adding comments with an image button. At first it sounded easy. Just replace the <CSControl:ResourceLinkButton /> with an <asp:ImageButton />. Not so fast, the compiler said. The <CSBlog:WeblogPostCommentForm /> was looking for a link button that inherits from CSLinkButton. Of course, the built in image button does not do that. So my solution, create my own custom composite control that inherits CSLinkButton but generates a link button.
Here's how I did it:
First, create a new control in the CommunityServerControls20 project (anywhere is fine but I put it in a new folder called "Custom") and call it CustomImageLinkButton.cs.
Add the following code:
using
System;
using
System.ComponentModel;
using
CommunityServer.Components;
namespace
CommunityServer.Controls
{
public
class
CustomImageLinkButton
:
CSLinkButton
{
[
Bindable
(
true
)]
public
virtual
string
ImageUrl
{
get
{
object
state = ViewState[
"ImageUrl"
];
if
(state !=
null
)
{
return
(
string
)state;
}
return
""
;
}
set
{ ViewState[
"ImageUrl"
] =
value
; }
}
protected
override
void
OnPreRender(
EventArgs
e)
{
base
.OnPreRender(e);
if
(!
Globals
.IsNullorEmpty(ImageUrl))
{
System.Web.UI.WebControls.
Image
image =
new
Image
();
image.ImageUrl = ImageUrl;
this
.Controls.Add(image);
}
}
}
}
When you create the control in the UI and pass in an ImageUrl, the control creates an image object and adds it to the links control array. That's it.
Here is the UI code in action:
<
CSBlog
:
WeblogPostCommentForm
ID
="WeblogPostCommentForm1"
runat
="server"
>
... snip ...
<
FormTemplate
>
<
div
class
="CommonFormArea">
... snip ...
<
div
class
="CommonFormField">
<
br
/>
<
CSControl
:
CustomImageLinkButton
runat
="server"
ID
="btnSubmit"
ImageUrl
="http://localhost/project1/images/submit.jpg"
ValidationGroup
="CreateCommentForm"
/>
</
div
>
</
div
>
</
FormTemplate
>
</
CSBlog
:
WeblogPostCommentForm
>
Enjoy!
Wednesday, August 15, 2007 @ 09:50 AM (-07:00) Pacific Daylight Time
Comments (0)
tags:
Community Server
|
Programming
admin: Edit | Remove
Name
E-mail
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
Site Navigation
About Me
Calendar
Disclaimer
Site Search
Sponsored Links
Calendar
<
November 2008
>
Sun
Mon
Tue
Wed
Thu
Fri
Sat
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Monthly Archives
August, 2008 (1)
July, 2008 (1)
March, 2008 (2)
January, 2008 (3)
December, 2007 (3)
October, 2007 (1)
September, 2007 (1)
August, 2007 (5)
July, 2007 (5)
June, 2007 (3)
April, 2007 (5)
February, 2007 (2)
January, 2007 (2)
December, 2006 (9)
November, 2006 (15)
October, 2006 (19)
September, 2006 (3)
August, 2006 (5)
July, 2006 (4)
June, 2006 (6)
May, 2006 (12)
April, 2006 (20)
March, 2006 (11)
February, 2006 (14)
January, 2006 (14)
December, 2005 (23)
November, 2005 (23)
October, 2005 (42)
September, 2005 (4)
Categories
Alert (14)
Community Server (2)
Daily Quote (1)
Did you know (7)
Dumb Searches (1)
Dumbass (15)
General (133)
Haiku (6)
Holiday (5)
Movie quote (8)
Paladin (4)
Paris (1)
Parody (1)
Photo (24)
Political (2)
Priceless (7)
Programming (35)
Pytheus (2)
Rant (23)
Screen capture (15)
SQL (3)
Technical (39)
Video (4)
Vista (8)
Visual Studio 2005 (2)
Wifey (33)
XP (1)
Feeds
RSS
Atom
Good Reading
Code Better
Coding Horror
Computer Zen
Daily WTF
Days Bush Has Left
Dooce
Fargg
Me-Nikk
Post Secret
Rory Blythe
TechCrunch
Sign In