views:

100

answers:

2

Hi,

I have a search page, you input some text in the input box and click search. It shows you the search results. The search click in just a href tag.

I have to perform a search manually sometimes i.e. without the user clicking on the search link.

So I did this via jqeury:

$("#hrefId").click();

The page posts back fine, but for some reason the value in the textbox is not being used by the search.

What could be the reason?

Update The outputted HTML for the link looks like:

<a id="ctl00_content_ctl00_fragment_2657_ctl00_ctl01_ctl00_SearchButton" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$content$ctl00$fragment_2657$ctl00$ctl01$ctl00$SearchButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">Search</a>
+1  A: 

What you are doing there is binding the click event (overriding an already bound one would be my guess).

Try $("#hrefId").trigger("click");

Fabian
A: 

Not sure why the form field isn't being passed through, but another work around is to call the postback method directly in the JavaScript, something like:

__doPostBack('<%= hrefId.UniqueID %>','');
wows