Nested Asp.Net Form

I need to provide an html form (not a server form) to search on the asp.net website. The form will be sent to another site where the indexed search is performed. Seeing how nested forms work poorly in asp.net, why is this the easiest way?

The nested form is a simple html form that does a “get” on a search website on which I have no programmatic control.

Update. I solved the problem by simply moving the server form to the desired location on the page, instead of surrounding the entire page. However, I'm still wondering how this will be handled if the html form needs to be placed physically between the server controls (which require the server form).

+3
source share
6 answers

However, I'm still wondering how this will be handled if the html form needs to be physically placed between the server controls (which require the server form).

You can place controls on your page without requiring an HtmlForm.

In your case, there is no problem declaring the markup of another form, but you can also just use some search control in your main form and force it to issue a GET to this website.

+2
source

" ", > 1 . - , : , <form runat="server"></form>. , ASP.NET, ?

.

+2

HTML! .

, ? , runat="server", , ( ), ​​ (.. ).

+1

, Server.Transfer() , , !

0

Try adding your HTML input elements wherever you want the nested form to be. Then use jQuery to change the page form action to point to an external website. The whole form is presented, but with a different external URL. A small drawback is the values ​​for all the input elements on the page, but in most cases this does not really matter.

(I just tried this using POST, not GET. This is basically a Roman O # 3 workaround in more detail)

<div id="nested-form">
    <input type="text" name="q">            
    <input name="searchbtn" value="Go" type="submit" class="search-button">
</div>

<script>
$(function() {
  $("input.search-button").click(function() {      
        $('form').get(0).setAttribute('action', 'http://external.com');
  });
});
</script>
0
source

Source: https://habr.com/ru/post/1713687/


All Articles