Click here to Skip to main content
15,887,596 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionWhich control can I use? Pin
ss.mmm20-Feb-08 11:28
ss.mmm20-Feb-08 11:28 
AnswerRe: Which control can I use? Pin
Christian Graus20-Feb-08 11:51
protectorChristian Graus20-Feb-08 11:51 
General(performacne) difference between Session and static class Pin
Seishin#20-Feb-08 11:03
Seishin#20-Feb-08 11:03 
GeneralRe: (performacne) difference between Session and static class Pin
Guffa20-Feb-08 11:33
Guffa20-Feb-08 11:33 
Questionconfusion over asynchronous methods inside web service Pin
ekynox20-Feb-08 10:31
ekynox20-Feb-08 10:31 
GeneralRe: confusion over asynchronous methods inside web service Pin
Venkatesh Mookkan20-Feb-08 15:49
Venkatesh Mookkan20-Feb-08 15:49 
GeneralRe: confusion over asynchronous methods inside web service Pin
ekynox21-Feb-08 9:53
ekynox21-Feb-08 9:53 
GeneralDynamic linkbuttons and event wiring Pin
Glenn E. Lanier II20-Feb-08 9:17
Glenn E. Lanier II20-Feb-08 9:17 
I have searched, with no success, for the answer to my problem. I want to dynamically create a linkbutton and programatically set the command to fire when the button is clicked. I can create the button, but the only event that seems to fire is the Page_Load. A simple example is below:

---- File: Test1.aspx ----
<code>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test1.aspx.cs" Inherits="ReportCard.Test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

</div>
</form>
</body>
</html>
</code>
---- File: Test1.aspx.cs ----
<code>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NLog;
using System.Text;

namespace ReportCard
{
public partial class Test1 : System.Web.UI.Page
{
public static Logger logger = LogManager.GetCurrentClassLogger();
protected void Page_Load(object sender, EventArgs e)
{
logger.Info("Page_Load: Postback: {0}", Page.IsPostBack.ToString());
}

protected void Button1_Click(object sender, EventArgs e)
{
logger.Info("Button1_Click");
Table table = new Table();

int i = 1;
TableRow tr = new TableRow();

TableCell tdSysCode = new TableCell();
tdSysCode.CssClass = "tdSysCode";
tdSysCode.Text = string.Format("{0:000}", i);

TableCell tdSysname = new TableCell();
tdSysname.CssClass = "tdSysname";

LinkButton lb = new LinkButton();
lb.CommandName = "lbViewSystem_Click";
lb.CommandArgument = i.ToString();
lb.Command += new CommandEventHandler(lbViewSystem_Click);
lb.Text = string.Format("System {0:000}", i);

tdSysname.Controls.Add(lb);

tr.Cells.Add(tdSysCode);
tr.Cells.Add(tdSysname);

table.Rows.Add(tr);

table.ID = "tblSystemResults";
table.CellPadding = 0;
table.CellSpacing = 0;

TableHeaderRow thrHeader = new TableHeaderRow();
TableHeaderCell thSystemCode = new TableHeaderCell();
thSystemCode.Text = "System Code";

TableHeaderCell thSystemName = new TableHeaderCell();
thSystemName.Text = "SystemName";

thrHeader.Cells.Add(thSystemCode);
thrHeader.Cells.Add(thSystemName);

table.Rows.AddAt(0, thrHeader);
PlaceHolder1.Controls.Add(table);
}

protected void lbViewSystem_Click(object sender, CommandEventArgs e)
{
logger.Info("lbViewSystem_Click");
Literal1.Text = string.Format("Argument = {0} at {1}", e.CommandArgument, DateTime.Now.ToString("MM.dd.yyyy HHmmss"));
}
}
}
</code>

On initial load, click the button, display the link button, then click the link button. You should see a message, but nothing happens.

I've read about creating the link button in the page_load (or on_init) method, but haven't had any success with that either.

Any tips are appreciated.

--G
GeneralRe: Dynamic linkbuttons and event wiring Pin
Christian Graus20-Feb-08 11:50
protectorChristian Graus20-Feb-08 11:50 
QuestionRe: Dynamic linkbuttons and event wiring Pin
Glenn E. Lanier II21-Feb-08 3:07
Glenn E. Lanier II21-Feb-08 3:07 
AnswerRe: Dynamic linkbuttons and event wiring Pin
Glenn E. Lanier II21-Feb-08 4:10
Glenn E. Lanier II21-Feb-08 4:10 
GeneralProgrammatically Setting Virtual Direction Expiration Pin
crystal915420-Feb-08 8:17
crystal915420-Feb-08 8:17 
Questioncan i link my javascript to a slideshow Pin
young34520-Feb-08 7:38
young34520-Feb-08 7:38 
AnswerRe: can i link my javascript to a slideshow Pin
Not Active20-Feb-08 7:52
mentorNot Active20-Feb-08 7:52 
GeneralRe: can i link my javascript to a slideshow Pin
young34520-Feb-08 9:16
young34520-Feb-08 9:16 
GeneralRe: can i link my javascript to a slideshow Pin
Not Active20-Feb-08 13:05
mentorNot Active20-Feb-08 13:05 
GeneralRe: can i link my javascript to a slideshow Pin
young34520-Feb-08 20:11
young34520-Feb-08 20:11 
GeneralGet User.Identity.Name on login page Pin
AlexeiXX320-Feb-08 7:31
AlexeiXX320-Feb-08 7:31 
GeneralRe: Get User.Identity.Name on login page Pin
Not Active20-Feb-08 7:44
mentorNot Active20-Feb-08 7:44 
GeneralRe: Get User.Identity.Name on login page Pin
AlexeiXX320-Feb-08 7:51
AlexeiXX320-Feb-08 7:51 
GeneralRe: Get User.Identity.Name on login page Pin
AlexeiXX320-Feb-08 7:55
AlexeiXX320-Feb-08 7:55 
GeneralTextarea.Value Commit issue Pin
gavin lane20-Feb-08 0:58
gavin lane20-Feb-08 0:58 
GeneralRe: Textarea.Value Commit issue Pin
newc120-Feb-08 1:47
newc120-Feb-08 1:47 
QuestionHow to store dataview's data in a datatable Pin
dews turner20-Feb-08 0:54
dews turner20-Feb-08 0:54 
AnswerRe: How to store dataview's data in a datatable Pin
dews turner20-Feb-08 1:18
dews turner20-Feb-08 1:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.