Solved

OnCommand Link Button

Posted on 2006-07-13
6
295 Views
Last Modified: 2008-03-06
Hi,

in an iteration, I create a LinkButton, add attributes to it, and finally add this LinkButton to the Form Controls.


That is fine, what is not is adding the Command Event. Here is my code

            for (int i = 1; i % 6 != 0; i++)
            {
                if (Convert.ToInt32(Session["CurPage"]) != MyPgd.PageCount - 1)
                {
                    LinkButton NewButton = new LinkButton();
                    NewButton.CommandName = "PageNo";
                    NewButton.CommandArgument = (Convert.ToInt32(Session["CurPage"])+i).ToString();
                    NewButton.Command +=new CommandEventHandler(NewButton_Command);
                    NewButton.Text = (Convert.ToInt32(Session["CurPage"]) + i).ToString();
                    Nav.Controls.Add(NewButton);
                }
            }

    }

    void NewButton_Command(object sender, CommandEventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        Response.Write(e.CommandArgument.ToString());
        //SetPage(Convert.ToInt32(e.CommandArgument.ToString()));
    }

It writes nothing on the page, it is not firing.

Thanks in advance

Andrew
0
Comment
Question by:REA_ANDREW
  • 3
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17098948
Andrew,

1) What is 'Nav'?

2) .NET version?  1.1 or 2.0

Bob
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17098977
1) Nav is a Div with an ID of Nav and a runat="server"

2) Version 2.0


Andrew
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17099051
That doesn't help :(

Where is this called from?  Does it ever work?  Is there a post-back involved?  Something, anything to go on would help.

Bob
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17099080
All I want to do is dynamically assign a Command event to a link button which I make it the iteration.  Could you paste me a method which you think should work so I can try

Thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17107766
What is the page configuration?  Do you have a MasterPage?  Where is this code called from?

Bob
0
 
LVL 7

Accepted Solution

by:
skvikram earned 500 total points
ID: 17435395
a dynamically created link button can only be added in page controls collection so nav should be referring controls collection.

Additionallt it appears that
NewButton.CommandArgument = (Convert.ToInt32(Session["CurPage"])+i).ToString();

supplies only a number without a link. supply a link also
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now