所以我有一个创建<li>
元素的转发器。这是OnItemDataBound
var categoryList = (ProductCategoryObject) e.Item.DataItem;
var category = ((HtmlAnchor) e.Item.FindControl("category"));
category.HRef = "javascript:void(0);";
category.InnerText = categoryList.Name;
category.Attributes.Add("onclick", "javascript:$('#ProductCategory').val('" + categoryList.Id + "');$('button.product-categories span').text('" + categoryList.Name + "');");
这设置了隐藏类型输入的值,现在我的问题是如何在按钮点击时获得该值?它似乎在回发中消失,我已经尝试Request["ProductCategory"]
和Request.Form["ProductCategory"]
这是标记:
<div class="input-group margin-bottom-30">
<div id="divCategories" runat="server" class="input-group-btn">
<button type="button" class="btn blue dropdown-toggle product-categories" data-toggle ="dropdown">
<asp:Label runat="server" ID="lblCategory">All Categories</asp:Label> <i class="icon-angle-down"></i>
</button>
<ul runat="server" ID="ulCategory" class="dropdown-menu">
<asp:Repeater runat="server" id="rptCategories" OnItemDataBound="CategoriesOnItemDataBound">
<ItemTemplate>
<li>
<a runat="server" id="category"></a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<input id="ProductCategory" type="hidden" />
</div>
<asp:TextBox runat="server" ID="txtSearch" CssClass="form-control"></asp:TextBox>
<div class="input-group-btn">
<asp:LinkButton ID="btnFilter" runat="server" CausesValidation="True" ValidationGroup="BaseValidationGroup" CssClass="btn green" OnClick="SearchBtnOnClick"> Search <i class="icon-search"></i> </asp:LinkButton>
</div>
</div>
答案 0 :(得分:0)
所以我想通了,我必须从
更改输入控件的标记<input id="ProductCategory" type="hidden" />
到
<input id="ProductCategory" name="ProductCategory" type="hidden" />
所以,基本上,我错过了name
工作所需的Request.Form["ProductCategory"]
标记。