Using JavaScript to implement DBTextBox in Delphi!

xiaoxiao2021-03-06  47

Topic: Use JavaScript to implement Data-sensitive controls in Delphi DBTextBox! Keywords: JavaScript UserControl data sensitive

When we write a network database program, we often encounter such problems. In the editing page of the data (Note that data is not in the DataGrid), you often put some textbox to enter the data, then click "Save" or "Back "Buttons, if the user changed the data in TextBox, the" Return "button is not saved, it should be prompted that the user data is not saved. This feature is a data-sensitive control in Delphi, but in Delphi, it is generally written in C / S software, which will be largely different on the Web. How is this feature that implements it, you might think of the TextChange event with TextBox, when the text in the TextBox is changed, the server is notified, and then the corresponding prompt is made when you click "Return". However, there is an important issue here. If this is done, the page will generate postback every time, the efficiency of the execution will be big, this road is not available! If you can get it in the client, use JavaScript. Here is simple to talk about JavaScript: Since most Win programmers are used to the original development method, now go to the web to develop, may still maintain the original thinking, and there is not enough attention to JavaScript, this is incorrect ! Because if your web program wants to write well, don't understand HTML, JavaScript, CSS these things are not written. The words retired, and this feature is now realized by JavaScript. First, put a DBTextBox user control, inherited from System.Web.ui.userControl. Add the following code in this control: private void page_load (Object sender, system.eventargs e) {// Place the user code here to initialize the page // Write the client string tmpstr = @ "< Script language = "JavaScript"> var changing = false; "; response.write (tmpstr); SubtextBox.attributes.add (" onkeyup "," changing = true; ");} This code It means that when initializing this DBTextBox control, write a global variable "Changed" to the client, and initialize this variable is false. Then add the onkeyup attribute to Textbox, that is, if the customer has a button in this textbox, the global variable "Changed" is set to TRUE.

转载请注明原文地址:https://www.9cbs.com/read-62873.html

New Post(0)