Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OnCommand Link Button

Posted on 2006-07-13
6
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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