简体   繁体   中英

I get empty value from asp Hidden field

I am using a Hidden field and i set it when one of hyperlink options is clicked on the value will be stored in Hidden field and i can call it from code behind.However i get empty value

 <script type='text/javascript'> $(function(){ $('.dropdown-menu a').click(function(){ $("#<%= YourProperty.ClientID %>").val($(this).attr('href')); }); }); </script> 
 <ul class="dropdown-menu" role="menu"> <li><a href="#contains">Contains</a></li> <li><a href="#its_equal">It's equal</a></li> <li><a href="#greather_than">Greather than ></a></li> <li><a href="#less_than">Less than < </a></li> <li class="divider"></li> <li><a href="#all">Anything</a></li> </ul> 

  var selection = YourProperty.Value;
        grid.DataSource = U.Search(selection, txtsearch.Text);
        grid.DataBind();

I'm not sure where you get the value(which is empty). When you click on the hyperlink, you don't really trigger postback. It updates the value in the hidden value. On the other hand, I add a button. Once you click any hyperlink (and the hidden value is updated accordingly), you can retrieve that hidden value from code behind. You may put your data binding code within the event handler function.

<ul class="dropdown-menu" role="menu">
    <li><a href="#contains">Contains</a></li>
    <li><a href="#its_equal">It's equal</a></li>
    <li><a href="#greather_than">Greather than ></a></li>
    <li><a href="#less_than">Less than < </a></li>
    <li class="divider"></li>
    <li><a href="#all">Anything</a></li>
</ul>
<asp:HiddenField ID="YourProperty" runat="server" />
<asp:Button ID="btnGo" runat="server" OnClick="btnGo_Click" Text="Go!" />

code behind

protected void btnGo_Click(object sender, EventArgs arg)
{
    var yourPropertyValue = YourProperty.Value;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM