472,968 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,968 software developers and data experts.

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

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[i] ) {

// paint a Disabled button.
tTabRow = new TableRow();
tTabRow.BackColor = Color.Aqua ;
tTabCell= new TableCell();
tTabCell.Text = _arrTabs[i];
}
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[i];
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
}
}
Nov 18 '05 #1
0 1616

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
3
by: Chris | last post by:
Hi I have designed my website to fit my standard windows. I use a javascript scroller that nescitates the removal of the browser scroll bars. However if a user has an extra toolbar open in...
1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
3
by: Learner | last post by:
Hello, I have two buttons on one of my VehicleDetails.aspx page. Obiviously these two buttons takes the user to two different pages. Now my client is interested in having a linkbutton instead of...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
9
by: Jonathan Wood | last post by:
Greetings, My app displays users in a GridView control. I'd like to have the name field shown in each row of this control a link that displays another page with information about that user. ...
3
balabaster
by: balabaster | last post by:
I've got a user control that builds a table of dynamic data based on a :LINQ class holding the data. The data is loaded using the LoadData(DataInstance) method. The table it builds contains a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.