Implementation of HtmlButton Client control Web page submission in asp.net

Source: Internet
Author: User
Asp.net| Client | control | Web page We know that the appropriate use of HTML controls in the ASP.net is a lot of convenience, HTML controls can be scripted on the client, but also after the Web page submitted to the server in the CS file control, If you can't do this with a separate Web server control, it limits the flexibility we develop. So we'll use the HtmlButton control in a lot of places. Here's a little tip about the control:
If you want to click HtmlButton to submit the page, we will choose to run the HtmlButton as a server control. Doing this every time you click the HtmlButton will cause the page to be submitted to the server, but if we need to do some processing on the client after clicking the button, Then choose whether to make the page submission, according to the general processing method, it seems HtmlButton powerless, but we analyze the HtmlButton after the Web run generated HTML, generate HTML as follows:

<input language= "javascript" name= "Clientbutton" id= "Clientbutton" button "type=" style=; left:168px; Position:absolute; top:80px "value=" button "/>
We see that the generated HTML adds the OnClick event to the button, so that the page is submitted, and we know how it's going to be done, and if we do that before __doPostBack (' Clientbutton ', ') executes, Add a client to the button and then decide whether to submit this is not to meet our needs, we understand the principle of implementation, I do not say so Luo-lock, the following I said how to achieve:

1 We in the background CS file to HtmlButton attribute, where Clientbutton is HtmlButton for id,clientoper for client JavaScript function. Clientbutton. Attributes.Add ("onclick", "if (!clientoper ()) {return;}");
This sentence is typically placed in a Web page load event.
2 The client adds the Clientoper method, performs the action you want, and, after the operation completes, determines whether a submission is required based on the return value, returns true to the Web submission, and false does not commit.
<script language=javascript>
function Clientoper ()
{
You can perform client operations here, such as validation.
Here to determine whether to submit
var result=window.confirm ("Are you sure you want to submit?");
if (result)
{
return true;
}
Else
{
return false;
}
}
</script>
The method is also very simple, trust friends to see it, said that there are friends asked, but this only applies to HtmlButton, buttons, more rigid, if you want to do with the picture to do the button, the method of course, there is no need to modify what, study the button CSS style to meet your needs!

Well, if there is no understanding of the place, we discuss together, I wish you all the process of life colorful!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.