"There's a form on the page, some submit buttons or link buttons that need to be clicked to open a new page." How do we get these buttons to submit the form information to the correct page? ”
The question looks very simple.
Familiar with the ASP tutorial. NET development should be very clear, through the ASP.net tutorial webform, we can set the runat= "Server" form for property settings:
View sourceprint?1 <form method= "POST" action= "default.aspx" Id= "Form1" >
As you know, the method attribute is an HTTP data transfer approach, and the action attribute is the target page to be submitted, and the set target is _blank to open a new page.
For a typical page interaction, one or more buttons submit an identical form that does not matter, but if the button needs to post a different page, this method is powerless. Because this workaround is "global", set once, affecting all form submission elements.
2, the form of runat=server
Here, perhaps someone will "gloat" to say that this is the form of Web Form mechanism is not good, a page can only have a runat=server form. We can definitely define a few more form in one page, for different submit buttons, we give it a different form (that is, split the submit button to a different form), so do not solve the problem (Sina, NetEase and Sohu and many other pages, open a Web page and see the source code can see a lot of form, I guess that's the way it is?
However, this is not a unique "fault" of the Web form, and other development frameworks have similar problems
Simple and practical solutions
(1) Direct use of LinkButton or link controls?
In general, it is easy to think of using the properties of a ready-made link control to implement a page submission. Let's say LinkButton:
View sourceprint?1 <asp:linkbutton runat= "Server" id= "Btnnewtarget" text= "New Target"
2 target= "_blank" onclick= "Bnnewtarget_click"/>
Although LinkButton does not have the target attribute, it has no problem setting it up like the above.
But that's what scares the most, but. When viewing the generated HTML source code:
View sourceprint?1 <a id= "btnnewtarget" target= "_blank" href= "Web page Special Effects: __doPostBack (& #39;btnnewtarget& #39;, & amp; #39;& #39;) ">new target</a>
We found that the href attribute of a element in the generated HTML source code has been set to a familiar control postback script. This is the script that allows us to submit data to a new window in vain. Why, then?
Set the target for the form for these buttons!
With the following script, we can easily implement our predefined features:
View Sourceprint?1 $ ("#btnbuttonnewtarget, #btnnewtarget"). Click (function () {
2 $ ("form"). attr ("target", "_blank");
3});
For the same page post (the example is a Default.aspx page), it has a different effect than (1). Maybe you're used to asking why
so real "form submission process" happens? Following the original meaning, it looks as if the new page is open, and the previous page's form data is submitted to the newly opened page, which looks like the _dopostpack function of the previous page (current page) "jumps" to the currently open page (also known as page) triggers ClickHandler ... Isn't that the "current page" permutation? Perhaps my own understanding is still biased, the English level is falling crazy, must be filled. If you have a better understanding of the explanation, please do not hesitate to enlighten me.