Skip the following steps
Controls are very useful in Asp.net and greatly speed up development. In particular, server controls. I learned from Asp.net when I was developing the web site, and I thought that the website was just like this-NLP. it's right to do it anyway. As more and more things are learned, more and more people know the principles of the website. It is gradually discovered that the development speed of the server has been reduced by accelerating the development speed. More and more things are learned, and the development requirements are getting higher and higher. I am gradually not satisfied with server controls.
The server control enhances the processing capability in the background, but is sometimes restricted in the foreground. I am restricted.
I have been writing Java for a long time, and I think Java is writing a website quite fast. Suddenly, the boss told me on Tuesday that there is a. Net project here, so let me write it first. Then I went back to. NET and wrote Asp.net.
Since the website I wrote previously is not a job or a community website, I have been researching and working on the background, and have little contact with the front-end stuff. The website I wrote is not interactive. This is a company project, and I am still under a little pressure. It cannot be too bad.
With regard to the button Server Control, I have always wanted to reduce it by submitting data to the server. Those checks can be implemented on the client. This requires JavaScript, but I found that JavaScript alone is not enough. The click event of the button Server Control is called "onclick", so JavaScript cannot use this event. Because the name is duplicated. What I want to achieve is
When you click the button, run the client's JavaScriptCodeAnd then execute the background event.
If the HTML control is used, this problem does not exist. However, I want to implement this function of the server control, and sometimes the server control is also very useful.
Google, find
Method
FirstAspxPageAddA server control button
<Asp: button id = "button1" runat = "server" text = "Submit" onclick = "button#click"/>
During page initialization, give the button Server ControlAdd a client event. That is, inPage_load ()Add a code in this method:
Protected VoidPage_load (ObjectSender, eventargs e ){If(!Page. ispostback ){//Add client events to button1Button1.attributes. Add ("Onclick","Return jsfunction ()");
// Jsfunction () is a JS function }}
Jsfunction () is a JS function that is added on the ASPX page, for example
<Script language = "JavaScript">FunctionJsfunction(){
If(Confirm ("are you sure you want to add an employee? ")){Return True;}Return False;}</SCRIPT>
The above return true and false are very important, which determines whether to execute the data. The next execution should be to submit the data to the background to process the data. When true is returned, the background executes the button#click method (event ).
The preceding functions enable the server control button to execute JS before executing background code.