c# - asp hiddenfield get empty value from javascript parameter -
i trying pass value selected parameter in dropdown-menu
hidden-field
. have traced code see hidden-field
value , empty value.
also traced javascript code using browser debugger, no errors occurred. whats wrong?
javascript
$(document).ready(function (e) { $('.search-panel .dropdown-menu').find('a').click(function (e) { e.preventdefault(); var param = $(this).attr("href").replace("#", ""); var concept = $(this).text(); $('.search-panel span#search_concept').text(concept); $('[id$=hdnsearchparam]').val(param); }); });
code-behind
protected void btnsearch1_click(object sender, eventargs e) { grid.datasource = u.search(hdnsearchparam.value, txtsearch.text); grid.databind(); }
markup
<div> <div class="col-xs-8"> <div class="input-group"> <div class="input-group-btn search-panel"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span id="search_concept">filter by</span> <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li><a href="#username">username</a></li> <li><a href="#its_equal">it's equal</a></li> <li><a href="#greather_than">greather ></a></li> <li><a href="#less_than">less < </a></li> <li class="divider"></li> <li><a href="#all">anything</a></li> </ul> </div> <input type="hidden" name="search_param" value="all" id="search_param" /> <asp:textbox id="txtsearch" runat="server" class="form-control" name="x" placeholder="search term..."> </asp:textbox> <span class="input-group-btn"> <asp:linkbutton id="btnsearch" runat="server" cssclass="btn btn-primary" onclick="btnsearch1_click"> <span class="glyphicon glyphicon-search"></span> </asp:linkbutton> </span> </div> </div> </div> <asp:hiddenfield id="hdnsearchparam" runat="server" />
you cannot access asp.net control jquery/javascript without making update code. asp.net changes id of control @ run time. have 2 options:
use clientid actual id of control
var hiddenfield = $("#<%= hdnsearchparam.clientid %>");
set clientidmode static , jquery work is. (assuming you're using .net 4.0 or above)
<asp:hiddenfield id="hdnsearchparam" runat="server" clientidmode="static" />
more clientidmode
Comments
Post a Comment