How do I post back information from a webpage that has post-generated content?

Posted by meanbunny on Stack Overflow See other posts from Stack Overflow or by meanbunny
Published on 2012-07-02T22:22:36Z Indexed on 2012/07/03 15:16 UTC
Read the original article Hit count: 198

Filed under:
|
|

Ok so I am very new to html and the web. Right now I am trying to generate list items on the fly and then have them post back to the web server so I know what the person is trying to obtain.

Here is the code for generating the list items:

foreach (var item in dataList) {
    MyDataList.InnerHtml += "<li><a runat='server' onclick='li_Click' id='" + item.Name + "-button'></a></li>";
}

Further down I have my click event.

protected void li_Click(object sender, EventArgs e) {
    //How do I determine here which item was actually clicked?
}

My question is how do I determine which list item was clicked?

Btw, the code running behind is C#.

EDIT 1

LinkButton link = new LinkButton();
link.ID = "all-button";
link.Text = "All";
link.Click += new EventHandler(link_Click);
MyDataList.Controls.Add(link);

Then below I have my link_Click event that never seems to hit a breakpoint.

void link_Click(object sender, EventArgs e) {
    if (sender != null) {
        if (sender.GetType() == typeof(LinkButton)) {
            LinkButton button = (LinkButton)sender;
            if (button.ID == "all-button") {

            }
        }
    }
}

I know this has to be possible I just cant figure out what I am missing.

Edit 2

Ok ok I think I know what the problem is. I was trying to add a second list inside of another list. This was causing the whole thing to have problems. It is working now.

© Stack Overflow or respective owner

Related posts about c#

Related posts about html