Reputation: 10561
I have two forms on an asp.net page. One is the overall form tag, with runat="server"
and the other is a simple form with one input for search.
The form itself:
<form method="post" id="searchForm">
<input type="text" id="searchstring" class="search-box" name="searchstring"
value="Search..." />
</form>
the Razor script to check for postback:
@{
bool isPostBack = !String.IsNullOrEmpty(Request.Form["searchstring"]);
var original_value = "Search...";
if(isPostBack)
{
Response.Redirect("/SearchResults/?q=" + Request["searchstring"]);
}
}
This is submitted via jQuery on enter like so:
$(document).ready(function() {
var $search = $('#searchstring');
original_val = "@original_value";
$search.focus(function() {
if ($(this).val() === original_val) {
$(this).val('');
}
}).blur(function() {
if ($(this).val() === '') {
$(this).val(original_val);
}
}).keypress(function(e) {
if (e.which == 13) {
$('form#searchForm').submit();
}
}); });
My problem is that once I put the search form on the page, server-side forms get disabled. For example: I have a regular asp.net membership login control, which stops posting back once the search form is on the page.
I looked around on google for a bit, but all I could find are people talking about two SERVER side forms on one page. Maybe this is trivial, but I can't get it working.
Thank you!
Upvotes: 0
Views: 74
Reputation: 6454
You are probably nesting the two forms. In this case, the outer one (or the inner one, depending on the browser) won't work.
Fixing this is quite easy: just move the contained form outside of its containing form.
Upvotes: 1