为什么我的ASP.NET LinkBut​​ton没有触发OnClick ="AddToCart_Click"事件?

Baz*_*nga 7 c# asp.net e-commerce

我现在一直在撞墙挡住整整一天.我正在研究Apress的"在C#中开始使用ASP.NET电子商务",如果有人熟悉该项目的话.在第10章中,我们正在使用PayPal AddToCart和GoToCart功能.这是未触发的事件:

    //Why is this not working?
protected void AddToCartButton_Click1(object sender, EventArgs e)
{
    string productID = Request.QueryString["ProductID"];
    ProductDetails pd = CatalogAccess.GetProductDetails(productId);
    string options = "";
    foreach (Control cnt in attrPlaceHolder.Controls)
    {
        if (cnt is Label)
        {
            Label attrLabel = (Label)cnt;
            options += attrLabel.Text;
        }
        if (cnt is DropDownList)
        {
            DropDownList attrDropDown = (DropDownList)cnt;
            options += attrDropDown.Items[attrDropDown.SelectedIndex] + "; ";
        }
    string productUrl = Link.ToProduct(pd.ProductID.ToString());
    string destination = Link.ToPayPalAddItem(productUrl, pd.Name, pd.Price, options);
    Response.Redirect(destination);
    }
Run Code Online (Sandbox Code Playgroud)

这是LinkBut​​ton的代码:

    <p>
    <asp:LinkButton ID="AddToCartButton" runat="server" CausesValidation="False" OnClick="AddToCartButton_Click1">Add to Shopping Cart</asp:LinkButton>
</p>
Run Code Online (Sandbox Code Playgroud)

我尝试过设置断点,但从未达到过该事件.LinkBut​​ton也会导致回发,但永远不会触发OnClick事件.

任何帮助将非常感激!

这是网址:http://www.northarktest.net/edwards/balloonshop

似乎click事件在服务器上触发,但在本地调试时.

Ash*_*rma 1

我想确实LinkButton会引发该OnClick事件。也许该方法AddToCartButton_Click1()重定向到错误的 URL,请重新检查此行:

string productUrl = Link.ToProduct(pd.ProductID.ToString());
string destination = Link.ToPayPalAddItem(productUrl, pd.Name, pd.Price, options);
Response.Redirect(destination);
Run Code Online (Sandbox Code Playgroud)

为什么?单击“添加到购物车”链接按钮后,我得到了以下 URL:http://www.northarktest.net/edwards/balloonshop/Im-Younger-Than-You-p22/?ProductId=22

现在,如果您发现 URL 中缺少页面,则该页面应该包含以下内容:abc.aspx?ProductId=22