Solved

OnCommand Link Button

Posted on 2006-07-13
6
337 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
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

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!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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