Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Retrieving value from INPUT element

$
0
0

I am trying to retrieve the value entered by the user from an INPUT element for a text box called "txtSearch" that is defined in the master page called Store.master I am trying to retrieve this through a function in code behind for a page called Listing.aspxWhen I run the application the value of "txtSearch" is always null even if a value is typed in the text box.

When you type a value in the text box does it have to be submitted or posted before it can be retrieved? Any help about resolving this would be greatly appreciated.

===============================
Store.Master
===============================

<input type="text" style="width: 125px; padding-bottom: 5px;" id="txtSearch" name="search" runat="server"/>

===============================
Listing.aspx.cs
===============================

private IEnumerable<Product> FilterProducts()

{
  IEnumerable<Product> products=repo.Products;
  string currentCategory=(string)RouteData.Values["category"] ??
  Request.QueryString["category"];
            
  if (currentCategory == "Search")
  {
     string searchitem = Request.Form["txtSearch"];
     return currentCategory == null ? products
        : products.Where(p => p.Name.Contains(searchitem));
  }

  else
  {

     return currentCategory == null ? products
        : products.Where(p => p.Category == currentCategory);
  }
}


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>