Development Environment v. S. 2008. Net 3.5
Symptom:
The work filling page contains the widget and a submit button.
In the script in the background, there is a button OnClick event
Event content
If the storage fails, a friendly message indicating that the storage is unsuccessful is displayed.
The same is true for success.
The script code is as follows:
This. Response. Write ("<script> alert ('storage failed! ') </Script> ");
After running, click "save failed". A dialog box is displayed, but the style is lost.
Cause:
When this. Response is used in the background, the script will be added to the back-to-customer stream before the Render method, and then the Page
When the page ends, call render () to generate a normal page stream and add it to the stream sent back to the client. What the browser receives is
<Script> alert ('Storage failed! ') </Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
</Head>
<Body>
</Body>
</Html>
Such a combination may sometimes cause style loss (in this case, the style may be lost due to different reasons) (the browser cannot parse it correctly)
Solution
In summary, it is to register the client code through the background.
The following is a simple example.
ClientScriptManager cs = Page. ClientScript;
Cs. RegisterClientScriptBlock (typeof (Object), "alert", "<Script> window. alert ('fault ticket submitted successfully, serial number:" + GetFaultInfo (). Fault_NO + "! ') </Script> ", True );
Note that the last True must be added when assigning values to the method. In this way, you can rewrite the script block with the same name on the page.
ClientScriptManagerClass is used to manage client scripts and add them to Web applications.
In Shanghai