Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2010, 05:59 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default Issue with Dynamically created control Click_event

I have a ASP Button control 'B'. I want some linkbuttons to be created in the Click event of the 'B' button. And inturn i want some functions to be done in the click event of the Linkbuttons created.

But when i click the Linkbutton, it disappears during page_load event.

So how i can recreate the LinkButton in page_load event since i want the linkbutton to be created only when i click the 'B' button?Please help.

My code behind:

in .aspx page i have:
<asp:Button ID="search" runat="server" OnClick ="B_Click" Text="Click" />


.aspx.cs
--------
protected void B_Click(object sender, EventArgs e)
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnkB1";
Form.Controls.Add(lnk);
lnk.Text = "lnkClick";
lnk.Click += new EventHandler(lnk_Click);

Page.EnableViewState = false;


}

protected void lnk_Click(object sender, EventArgs e)
{

LinkButton lnk = (LinkButton)sender;
lnk.Text = "Thanks for clicking me";


}
 
Old May 18th, 2010, 03:12 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The easiest way would be to always have the link button there, just set it to invisible, and make it appear when you click the B button.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 19th, 2010, 12:32 AM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thanks. That helped.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing dynamically created content in a literal control ericburnley C# 2005 4 March 4th, 2010 05:09 PM
Please help me about dynamically created controls vingo_mail ASP.NET 2.0 Basics 1 March 24th, 2008 12:54 PM
Saving Data to DB in dynamically created control ashokkumar ASP.NET 1.0 and 1.1 Basics 2 June 23rd, 2006 01:18 PM
Dynamically created code Puck312 Pro VB 6 3 September 7th, 2005 01:21 PM
Dynamically created controls katsarosj ASP.NET 1.0 and 1.1 Basics 4 February 4th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.