Need help: How to Repaint a User Control with Dynamic ASP Link Buttons

R

RSB

Hi Every one,
i am trying to create a UserControl and i am passing a Array of strings to
it. Now based on the Array elements i am creating the LinkButtons
Dynamically. I am also passing a Event to this control and Lining the
OnClick event of these LinkButtons to this Event. (Which works fine).

Now the Thing which i cannot achieve is i want to Change the Back Color of
the Clicked to LinkButton To a different color and i also don't want to
Display the clicked item as LinkButton. and i am not able to do that. Looks
like i am missing some thing here. Please Help me..

Here is the code of all my Files.

1:- test2.aspx File. ( in this file i am calling the Control)


<%@ Register TagPrefix="uc1" TagName="Tabs" Src="Tabs.ascx" %>
<%@ Page language="c#" Codebehind="test2.aspx.cs" AutoEventWireup="false"
Inherits="MY.LIB.TabsProject.test2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test2</title>
</HEAD>
<body>
<form id="test2" method="post" runat="server">
<P>
<asp:placeHolder id="PH1" runat="server"></asp:placeHolder></P>
<P>
<uc1:Tabs id="Tabs1" runat="server"></uc1:Tabs></P>

</form>
</body>
</HTML>




2:- test2.aspx.cs File.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MY.LIB.TabsProject
{
/// <summary>
/// Summary description for test2.
/// </summary>
public class test2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder PH1;
protected TabsProject.Tabs Tabs1 ;



EventHandler eh;


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

Tabs1.SetMenuItemCaptions (new String[]
{"test1","test2","test3","test4","test5","test6"});
eh = new EventHandler(this.MenuButtonClicked);
Tabs1._eh=eh;
Tabs1.getTabsTable("test1" );
}
private void MenuButtonClicked(object sender, System.EventArgs e) {
LinkButton lb = (LinkButton) sender;

Response.Write("The property is " +lb.Text);
if (lb.Text.CompareTo("test1")== 0) {
Test1Clicked();
}
else if (lb.Text.CompareTo("test2")== 0) {
Test2Clicked();
}
else if (lb.Text.CompareTo("test3")== 0) {
Test3Clicked();
}
else if (lb.Text.CompareTo("test4")== 0) {
Test4Clicked();
}
else if (lb.Text.CompareTo("test5")== 0) {
Test5Clicked();
}
else if (lb.Text.CompareTo("test6")== 0) {
Test6Clicked();
}



}
private void Test1Clicked(){
Response.Write ("<BR>TEST1 Clicked");
Tabs1.getTabsTable("test1");
}
private void Test2Clicked(){
Response.Write ("<BR>TEST2 Clicked");
Tabs1.getTabsTable("test2");

}
private void Test3Clicked(){
Response.Write ("<BR>TEST3 Clicked");
Tabs1.getTabsTable("test3");
}
private void Test4Clicked(){
Response.Write ("<BR>TEST4 Clicked");
Tabs1.getTabsTable("test4");
}
private void Test5Clicked(){
Response.Write ("<BR>TEST5 Clicked");
Tabs1.getTabsTable("test5");
}
private void Test6Clicked(){
Response.Write ("<BR>TEST6 Clicked");
Tabs1.getTabsTable("test6");
}

#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

}
}





3:- Tabs.ascx file.


<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Tabs.ascx.cs"
Inherits="MY.LIB.TabsProject.Tabs"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:placeHolder id="PH1" runat="server"></asp:placeHolder>


4:- Tabs.ascx.cs file.

namespace MY.LIB.TabsProject
{
using System;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public abstract class Tabs : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.PlaceHolder PH1;

string[] _arrTabs;
public EventHandler _eh;



/// <summary>
/// Set the Menu ITem List. The List is passed as an array
/// </summary>
public void SetMenuItemCaptions(string[] ItemList) {
_arrTabs = ItemList;
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public void getTabsTable(string CurrentDisplayTab ) {
this.PH1.Controls.Add (gettheTable(CurrentDisplayTab));
}

private Table gettheTable(string DisplayTab ){


// start of the table "tblMenu"
Table tblMenu = new Table(), tblTab;
tblMenu.Width = Unit.Percentage(100);
tblMenu.BackColor = Color.FromName("#ffffff");

TableRow row = new TableRow();
TableRow tTabRow;
TableCell cell, tTabCell ;
LinkButton lbTab;

//loop thru the Array of TABS.
for(int i = 0; i<_arrTabs.Length ; i++){

//add a space holder
cell = new TableCell();
cell.Width = Unit.Percentage(1);
cell.Text = "&nbsp;";
row.Cells.Add (cell);

cell = new TableCell();
cell.Width = Unit.Percentage(1);
tblTab = new Table();

// the Button should be Disabled if it is a Current Selected

if (DisplayTab ==_arrTabs ) {

// paint a Disabled button.
tTabRow = new TableRow();
tTabRow.BackColor = Color.Aqua ;
tTabCell= new TableCell();
tTabCell.Text = _arrTabs;
}
else {

//paint a Button with a Hyper Link.
tTabRow = new TableRow();
tTabRow.BackColor = Color.Coral ;
tTabCell = new TableCell();

lbTab = new LinkButton();
lbTab.Click += new EventHandler(_eh);
lbTab.BorderStyle = BorderStyle.Solid;
lbTab.Font.Name = "Arial";
lbTab.Text = _arrTabs;
tTabCell.Controls.Add (lbTab);
}
// the of ends here..
tTabRow.Cells.Add (tTabCell);
tblTab.Rows.Add (tTabRow);
cell.Controls.Add (tblTab);
row.Cells.Add (cell);
}
cell = new TableCell();
cell.Width = Unit.Percentage(1);
cell.Text = "&nbsp;";
row.Cells.Add (cell);
tblMenu.Rows.Add(row);
return(tblMenu);
}
#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);
}

/// 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
}
}
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top