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!