?
Solved

OnCommand Link Button

Posted on 2006-07-13
6
Medium Priority
?
344 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 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