Solved

OnCommand Link Button

Posted on 2006-07-13
6
334 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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