.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Custom Web Server Control

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net


I am creating a check box list web control. How do I get a values of the selected items into a variable, which can be accessed by the client to get the value. 

thanks in advance

My code

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:MultiSelectDDListWip runat=server></{0}:MultiSelectDDListWip>")> _
Public Class MultiSelectDDListWip
    Inherits CheckBoxList
    Public SelectedValues As String

    Public Overrides Sub RenderControl(ByVal output As HtmlTextWriter)

        Dim selectedValue = [String].Format("<b>Selected Values:</b><br/>{0}", String.Join(",", Me.Items.Cast(Of ListItem)().Where(Function(a) a.Selected).[Select](Function(a) a.Text).ToArray()))

View Complete Post

More Related Resource Links

video tutorial link for composite and rendered custom server control


hii all

i am new to technology so go easy on this post

according to what i read from web there are 3 type of custom server controls

1 superclass

2 composite

3 rendered

i found video tutorial for superclass custom server control but couldnt find video tutials for other 2.

please forward me link for composite and rendered custom server controls video tutorial  

image inside custom server control



I want to use an image inside a Custom Web server control ! 

Do I need to use Web.resources ? if so , how to do ?

Custom Server Control Property not maintaining state


I have created a server control consisting of a TextArea and a div under it.  My goal is to create my own asp:TextArea type control.  the div is for a Character count of the text area and seems to work ok but i added a CharacterCountVisible property to the control that is always returning true.  See Proptery definition below


<Bindable(False), Category("Appearance"), DefaultValue("True"), Localizable(True)> Property CharacterCountVisible() As Boolean
        Return _CountBoxVisible
    End Get
    Set(ByVal value As Boolean)
        _CountBoxVisible = value
    End Set
End Property

Note the _CountBoxVisible variable is define inside the class as :

Dim _CountBoxVisible as Boolean = True

What I am trying to do is give the user/coder the option to show/utilize the char count feature.  Can make it disappear with textarea1.CharacterCountVisible = False but setting it to true will not make it display.


What am i missing





custom server control with custom child collection,get the collection?

Hi!I want to create a custom server control, that then will have a custom child collection.The thing is that I also want to be able to modify the custom childs from the custom server control classFor example I have a row of cards, and the class is called CardRow, a CardRow is simply a class full of the class card in this case, se the class "Card" down below:using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections.Generic; namespace MemoryLib { [ToolboxData("<{0}:CardRow runat=server></{0}:CardRow>")] public class CardRow : WebControl { public List<Card> _Card; [PersistenceMode(PersistenceMode.InnerProperty)] public List<Card> Card { get { return _Card; } set { _Card = value; } } public CardRow() { } protected override void CreateChildControls() { } protected override void Render(HtmlTextWriter writer) { } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MemoryLib

How to embed jquery library in ASP.NET Custom Server Control

i created custom server control using jquery. i  embeded  jquery library in the control using following code. but it displays object expected error.  has someone done this before ?   //other code    protected override void RenderContents(HtmlTextWriter output) {    output.Write("<div id=\"bckPopup\"></div>"); }   protected void onInit(EventArgs e) { Page.ClientScript.RegisterClientScriptResource(GetType(), "HelpServerControl.Scripts.jquery-1.4.1.min.js");   string javascript = "<script type='text/javascript'> " +   "$(document).ready(function () { " +   "$('#bckPopup').text(\"loaded\"); " + "});</script>" ;   if (!(Page.ClientScript.IsClientScriptBlockRegistered("bhelp" ))) Page.ClientScript.RegisterStartupScript(this.GetType(), "bhelp" , javascript); base .OnInit(e);   }      

Dynamic ModalPopupExtender within a Custom server control

Hi folks,   I have this piece of code which paint an ImageButton and show a dynamic ModalPopupExtender (with 2 buttons btnGuardar and btCancel). The issue is neither btGuardar.Click nor btHidden.Click events are raised but ImageButton Click event is raised correctly. Please can you help mee?  protected HtmlGenericControl _divControlContainer = new HtmlGenericControl(); protected ModalPopupExtender _PopupHandler = new ModalPopupExtender(); protected override void CreateChildControls() { Page.Trace.Write("void CreateChildControls()"); _divControlContainer = new HtmlGenericControl("ivContenedor"); Button btHidden = new Button(); btHidden.ID = "hiddenTargetControlForModalPopup"; btHidden.Style.Add(HtmlTextWriterStyle.Display, "none"); btHidden.Click += new EventHandler(event_HiddenTargetModalPopup_Click); //EVENT NOT RISED _divControlContainer.Controls.Add(btHidden); ImageButton ib = new ImageButton(); ib.ID = "btUploadImage"; ib.ImageUrl = "~/Imagenes/UIControlImageViewer/upload.png"; ib.Height = new Unit("16px"); ib.Width = new Unit("16px"); ib.Click += new ImageClickEventHandler(event_UploadFile_Click); //EVENT RAISED CORRECTLY _divControlContainer.Controls.Add(ib);

unable to trace value after postback within Custom Server Control

public class TextBox : AStateManagement, IControl { #region "Variables" #region "Local Variables" protected System.Web.UI.WebControls.WebControl _TextBox = null; protected string _CssClass = string.Empty; protected string _Text = string.Empty; protected bool _Visible = true; protected bool _Enabled = true; protected string _ID = string.Empty; protected bool _IsViewStateLoaded = false; #endregion "Local Variables" #region "Global Variables" #endregion "Global Variables" #endregion "Variable" #region "Constructor" public TextBox() { _TextBox = new System.Web.UI.WebControls.TextBox(); _TextBox.ID = this.UniqueID; } #endregion "Constructor" #region "Events" #endregion "Events" #region "Disposable" #endregion "Disposable" #region "Properties" public override string CssClass { get { return _CssClass; } set { _TextBox.CssClass = _CssClass = value; } } public virtual string Text { get { return _Text; }

Custom server control Books and URLs


Hi all,
      I am new to custom server control. I want to create my own grid like custom server control for my project. Please suggest me some good books and urls.


CollapsiblePanelExtender within custom server control


I am trying to use a collapsible panel extender within a custom server control.  I've used the extender elsewhere with no issues but when I try to add the control to  my panels collection of controls in my custom control, my page crashes.  Take it out and no error.  I'm adding other controls to the panel...literals, labels, etc.  This, however is the only ajax control I am using.  Is there something I need to do as far as registering the extender with the script manager (on the master page)?  Thanks....Brad

client side functionality in a custom server control using vb?



is it posible to add client side functionality to a custom server control in vb.net?

i am looking at msdn library and there is no code for vb :/ http://msdn.microsoft.com/en-us/library/aa719700%28v=VS.71%29.aspx

I fount this on MSDN Library Adding Client Capabilities to a Web Server Control

What i'm trying to do is to add some client functionality to my control, so that you can get or set some properties/values on client side. From the above link i see  that this is doable with Ajax Server Control, but i don't have it, i have Custom Server Control. Can i do this with Custom Server Control and how?

Thank you.

Page Life Cycle and custom composite server control life cycle



We are creating a composite server control. It will have few other controls. I am confused where exactly to write the code ie in which event. Is page life cycle and control life cycle follow the same event order?

Could any one please suggest or post articles on this.

Thank You

Embedded Javascript File in Custom Server Control



I am creating a custom server control, and I am wanting to include a JavaScript file in the dll file when the control is built. I have tried suggestions from the following websites:




But after following the directions, If I use firebug to see what errors show up, the JavaScript functions that are being called all say "goNext is not defined" which leads me to believe the JavaScript file is not being added correctly. 

Some information on what my control looks like

I have the JavaScript File in a folder called Script. The namespace of the project is CustomControl, and the Name of the project is MaskedDateTextbox.

In my AssemblyInfo I have the following:

button in custom server control


i can add buttons in my custom server control but  i can't handle button click event.  how can i do this 

How to use a custom server control that is defined in inline code in the same page?




I have to use inline code for an aspx page and I need to use a custom server control that is defined in the same aspx page but the control does not get processed as a server control. it gets  returned as is as static html tag.


does anyone know how to do that?





EventHandling of custom server control that inherit Panel


I am developing a server control that inherit Panel. The form layout is fine. As a panel is a container with different types of control and trigger different types of event.  Say,

        <cc1:MyPanel ID="MyPanel1" runat="server" Width="300px" Title="Enter a new contact"
            onCanel="cmdCancel_Click" >
                        <asp:TextBox ID="txtName"

Custom web server control - databinding issues


I've created very simple web server control appropiate for the task.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Drawing;

namespace CustomWeb

    public class ValuedLabel : Label

        public string Value { get { return _value; } set { _value = value; } }

        private string _value;

        public string IsMultiSelect { get { return _isMultiSelect; } set { _isMultiSelect = value; } }

        private string _isMultiSelect;


As you can notice, my control extends built-in Label control. I'm adding 2 properties. I've created class library and added .dll to my website's references. I've added my control on ToolBox and put it on .aspx page. What i'm doing with that control is adding it inside ItemTemplate of ComboBox which gets populated with ObjectDataSource.

                         <cc1:ValuedLabel ID="vLabel" runat="server" Text='<%# Eval("Name") %>' Value='<%# Eval("IDCategory") %>' IsMultiSelect='<%# Eval("MultiSelect") %>' ></cc1:ValuedLabel>
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend