How to Create Web Controls using ASP.NET Controls ?

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Hello All,

I am trying to write Web Controls and in most of the samples I came across,
I am seeing the following function where a HTML string is written to create
HTML Controls.


/// <summary>

/// Render this control to the output parameter specified.

/// </summary>

/// <param name="output"> The HTML writer to write out to </param>

protected override void Render(HtmlTextWriter output)

{

string TheHTMLString = FrameHTMLString() ;

output.Write(TheHTMLString) ;

}


Is it possible for me to use the asp:button or asp:panel in this webcontrol.
Also how will I setup events for such button click or panel mouse down
event?


Any suggestions please?

Thanks
Aand Ganesh
 
M

msnews.microsoft.com

Steve,

I saw your sample and also I created my control based on your combobox
sample.

But my page is not even showing up the control.

Can you please let me know what I am missing?

Thanks
Anand

////////// My code //////////


I created a control and it is not showing up in my Web Page?

Here is my control code. Below this code I have posted my Main Code which is
accessing this control.


/// WEB CONTROL CODE
using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Collections ;

namespace NobelSystemsControls

{

public class WebControlPickOneValue : System.Web.UI.WebControls.WebControl

{

ArrayList ListofAllValues = new ArrayList() ;

string SelectedValueName = "" ;

int SelectedIndex = -1 ;

public void PerformHandShake(ArrayList InList)

{

this.ListofAllValues = InList ;

}


/// <summary>

/// Render this control to the output parameter specified.

/// </summary>

/// <param name="output"> The HTML writer to write out to </param>

protected override void Render(HtmlTextWriter output)

{

}

protected override void CreateChildControls()

{

ListBox TheListBox = new ListBox() ;

foreach(string eachst in this.ListofAllValues)

{

TheListBox.Items.Add(eachst) ;

}

TheListBox.SelectedIndexChanged +=new
EventHandler(TheListBox_SelectedIndexChanged);

this.Controls.Add(TheListBox) ;

//base.CreateChildControls ();

}

private void TheListBox_SelectedIndexChanged(object sender, EventArgs e)

{

ListBox INListBox = (ListBox) sender ;

this.SelectedValueName = INListBox.SelectedItem.ToString() ;

this.SelectedIndex = INListBox.SelectedIndex ;

}

}

}



/// The MAIN Code calling the CONTROL



using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace WebApplication

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected NobelSystemsControls.WebControlPickOneValue
WebControlPickOneValue1;


private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

ArrayList ToGo = new ArrayList() ;

ToGo.Add("0") ;

ToGo.Add("1") ;

ToGo.Add("2") ;

ToGo.Add("3") ;

ToGo.Add("4") ;

ToGo.Add("5") ;

ToGo.Add("6") ;

ToGo.Add("7") ;

ToGo.Add("8") ;

ToGo.Add("9") ;

ToGo.Add("10") ;

this.WebControlPickOneValue1.PerformHandShake(ToGo) ;

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion




}

}









///////////// My code ////////////
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top