0

Solved I just used asp:Repeater for the buttons, way more efficient.

I'm creating multiple tables with a foreach cycle and each table contains a button that leads to a separate page. Here's the html code for the button only.

<form name='input' action='AuctionDetails.aspx' method='get'>
<input type='submit' value='Bid now' name='{5}'/>
</form>

Now, I have a lot of iterations (around 50) and ALL of the buttons work, except the first one. Even when I filter the results (returns fewer tables), all of the buttons work, except the first one.

Here's the full method.

private void FillPageAuctions()
{
    IEnumerable<AuctionClass> query = null;
    var context = new AuctionsEntities();

    string queryString = Request.QueryString.ToString();

    if (Request.QueryString.ToString() != "")
    {
        query = from e in context.Auctions
                where e.Category.Name == queryString
                select e;
    }

    else
    {
        query = from e in context.Auctions select e;
    }

    StringBuilder sb = new StringBuilder();

    if (query.Count() == 0)
    {
        sb.Append("There are no auctions in this category.");
    }

    else
    {
        foreach (AuctionClass auction in query)
        {
            string temp = auction.AuctionName;
            if (auction.AuctionName.Length > 12)
            {
                temp = auction.AuctionName.Remove(12);
                temp = temp + "...";
            } 

            sb.Append(String.Format(@"<table style='border: 1px solid #666666;
                float:left;
                width: 24%;
                margin: 0px 3px 3px 3px;
                text-align: center;'>
                <tr><th style='font-size: 18px'>{0}</th></tr>
                <tr><td><img src='{1}' height='100px' width='100%'/></td></tr>
                <tr><td>Price: ${2}</td></tr>
                <tr><td>Time Left: </td></tr>
                <tr><td>{3} hours</td></tr>
                <tr><td>{4} minutes</td></tr>
                <tr><td>
                <form name='input' action='AuctionDetails.aspx' method='get'>
                    <input type='submit' value='Bid now' name='{5}'/>
                </form>
                </td></tr></table>", temp, "Untitled.png", 
                auction.CurrPrice, 0, 0, auction.AuctionID));
        }
    }
    AuctionListLabel.Text = sb.ToString();
}
4

2 回答 2

0

如果您将提交按钮的名称更改为您有多少个值:name='/0-50/' 您可以创建一个简单的循环,该循环可以使用计数器变量返回正在提交的值。

于 2013-07-30T14:07:31.987 回答
0

在一个 ASP.NET 页面中,不能放置多个 Form 标签。

单一表单模型是实现 ASP.NET 状态维护功能的关键元素。由于页面总是发布到自己,运行时发现很容易检索和恢复上次访问期间保存的状态。虽然还有其他方法可以保存和恢复页面状态,但使用单一表单模型是迄今为止所有解决方案中最简单和最有效的。

于 2013-07-30T14:08:02.263 回答