473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1642

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.