花边管理软件官方网站

统一项目按钮外观

统一项目按钮外观

一种最简单的方法就是扩展Button。
这里我们举例用最常用的按钮、Add,Edit、Delete
Add一般是跳转URL,Edit也是跳转URL,Delete一般需要后台处理。
以下是源代码,请大家多多提意见。
   

/// <summary>
    
/// 
    
/// </summary>

    [
     ToolboxBitmap(
typeof(TDButton), "WebximumWebControl.TDButton.bmp"),
     Designer(
typeof(WebximumWebControl.TDButtonDesigner)),
    ]
    
public class TDButton : Button
    
{
        
/// <summary>
        
/// 超级链接
        
/// </summary>

        public string URL
        
{
            
get
            
{
                
if (ViewState["URL"== null)
                
{
                    
return string.Empty;
                }

                
else
                
{
                    
return Convert.ToString(ViewState["URL"]);
                }

            }

            
set
            
{
                ViewState[
"URL"= value;
            }

        }

        
/// <summary>
        
/// 
        
/// </summary>

        public TDButton()
        
{
            
this.Width = new Unit(60);
        }


        
/// <summary>
        
/// 
        
/// </summary>
        
/// <param name="writer"></param>

        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        
{
            
base.AddAttributesToRender(writer);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Display, 
"none");
        }


        
private bool _IsParentWindowOpen = false;
        
/// <summary>
        
/// 父窗口打开
        
/// </summary>

        public bool IsParentWindowOpen
        
{
            
get
            
{
                
return this._IsParentWindowOpen;
            }

            
set
            
{
                
this._IsParentWindowOpen = value;
            }

        }


        
/// <summary>
        
/// 
        
/// </summary>
        
/// <param name="writer"></param>

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        
{
            
if (string.IsNullOrEmpty(this.URL))
            
{
                
base.Render(writer);
                writer.Write(
"<a href='JavaScript:' onclick=\"document.getElementById('" + 

this.ClientID + "').click();\">"
                                                        + "<table width='" + Width + "' border='0' 

cellpadding
='0' cellspacing='0'>"
                                                          + "<tr>"
                                                          
+ "<td align='center' valign='middle' 

class='btsearch' style='cursor: pointer; height: 19px;'>"
                                                          + this.Text
                                                                
+ "</td>"
                                                            
+ "</tr>"
                                                        
+ "</table>"
                                                    
+ "</a>");
            }

            
else
            
{                
                
string strHTML = "<a href='JavaScript:' onclick=\"{0}='" + this.URL + "'\">"
                               
+ "<table width='" + Width + "' border='0' cellpadding='0' 

cellspacing
='0'>"
                                 + "<tr>"
                                 
+ "<td align='center' valign='middle' class='btsearch' style='cursor: 

pointer; height: 19px;
'>"

                                 
+ this.Text

                                       
+ "</td>"
                                   
+ "</tr>"
                               
+ "</table>"
                           
+ "</a>";
                
if (this.IsParentWindowOpen)
                
{
                    writer.Write(
string.Format(strHTML, "window.parent.document.location"));
                }

                
else
                
{
                    writer.Write(
string.Format(strHTML, "document.location"));
                }

            }

           
        }

    }


    
/// <summary>
    
/// 
    
/// </summary>

    public class TDButtonDesigner : ControlDesigner
    
{
        
/// <summary>
        
/// 
        
/// </summary>
        
/// <returns></returns>

        public override string GetDesignTimeHtml()
        
{

            TDButton oTDButton 
= (TDButton)this.Component;
            
return ("<a href='JavaScript:' onclick='document.location='" + oTDButton.URL + "' >"
                                               
+ "<table width='60' border='0' cellpadding='0' 

cellspacing
='0'>"
                                                 + "<tr>"
                                                 
+ "<td align='center' valign='middle' 

class='btsearch' style='cursor: pointer; height: 19px;'>"
                                                 + oTDButton.Text
                                                       
+ "</td>"
                                                   
+ "</tr>"
                                               
+ "</table>"
                                           
+ "</a>");
        }

    }

posted @ 2008-07-12 12:04  花边软件,花边管理软件,服装(鞋)管理软件  Views(614)  Comments(4Edit  收藏  举报
花边管理软件官方网站