473,398 Members | 2,525 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,398 software developers and data experts.

dynamically add linkbutton

HI, I got some difficulties in adding linkbuttons through C# coding. I added
a panel as follows:
<asp:Panel id="LblNav" Runat="server" Visible="True"
Height="4Px"></asp:Panel>
then I created a method to generate a few links and inserted into this
panel;
void RenderNav (int CurrentPage, int TotalPage)
LinkButton bn;
for (int i = 1; i <= TotalPage; i++)
{
bn = new LinkButton();
bn.ID = "link" + i.ToString();
bn.Text = i.ToString();
bn.CausesValidation = false;
bn.Command += new CommandEventHandler(NavigationLink_Click);
bn.CommandName = "Numbered";
bn.CommandArgument = i.ToString();
LblNav.Controls.Add(bn);
LblNav.Controls.Add(new LiteralControl(" "));
}
}

the event handler is:
void NavigationLink_Click ( Object sender, CommandEventArgs e ) {
switch ( e.CommandName ) {
case "First": _currentPageNumber = 1; break;
case "Last": _currentPageNumber = Int32.Parse ( TotalPages.Text ); break;
case "Next": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) + 1;
break;
case "Prev": _currentPageNumber = Int32.Parse ( CurrentPage.Text ) - 1;
break;
case "Numbered": _currentPageNumber =
Int32.Parse(e.CommandArgument.ToString()); break; }
BindData();
}

What I expected was, when I clicked the numbered link button, I should jump
to that page. However, it did not work. And the worse thing was, the
linkbutton list had gone when I clicked either of the buttons. There are
four more static linkbuttons in the page, while they all work very
beautiful. I added a break point in the NavigationLink_Click(), but I even
could not get in when I clicked the numbered linkbutton while I got in if I
clicked other four buttons (First, last, prev, and next).

Do you have any idea how to fix this problem? I am struggling with it for
two days...

Thanks!!!

HU
Nov 18 '05 #1
1 3537
Hi,

Are you calling RenderNav from Page_load ?

You should create dynamic control each and every time the page is load
(including post back).
Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

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

Similar topics

3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
8
by: simon | last post by:
On code behind file: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then Dim ctrl As New LinkButton ctrl.ID =...
4
by: Mike Lowery | last post by:
I have an ASP.Net page that simply generates a dynamic page using Response.Write() statements to generate the HTML. This works great except that one of the things I want to generate is a...
5
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
6
by: ree321 | last post by:
I have a linkbutton which is added to a column in a datagrid dynamically using a template I created. When I change the data in it by not databinding and then when I later retreive the data from the...
5
by: tshad | last post by:
I found I can create Template columns dynamically - as long as I don't use objects that need onclick events, such as a LinkButton. Textboxes and Labels work fine. I create the Template columns...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.