Solve the problem of using updatepanel in Ajax and then using response. Write (); and so on.

Source: Internet
Author: User
Use response. wrie (""); or page. registerstartupscript (); in Ajax-supported websites. There are two solutions: (1)System. Web. UI. scriptmanager. registerstartupscript to replace Page. clientscript. registerstartupscript ==> Function prototype:System. Web. UI. scriptmanager. registerstartupscript (contrl control, type, string key, string script, bool addscripttags ); ==> Parameters:Control ----------------- to register the Control ID of this JavaScript statement, as shown in the following example, the button ID btnunreporttype ------------------ is the type of the registered script block control, that is, the updatepanel type. This is generally used directly. getType (): the Key --------------------- is the name of the cirpt statement to be executed. If the name attribute script ---------------- of the control is set to true, you do not need to write JavaScript labels for the script parameter on the front. If the value is false, you need to add the <script language = 'javascript '> </SCRIPT> label for the script parameter on your own.
Note: One more control parameter is required. If the control is in updatepanel, the operation is completed. If the control is not in updatepanel, this step is not allowed. ==> Eg. System. Web. UI. scriptmanager. registerstartupscript(Btnunreport, this. GetType (), "unreport", "alert ('failed to cancel the reporting operation. Please check the subject to be handed in! '); Window. Close (); ", true ); (2) dataitem registration method:Example: <% @ page Language = "C #" autoeventwireup = "true" codefile = "webform1.aspx. cs" inherits = "webform1" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Asp: scriptmanager id = "scriptmanager1" runat = "server"> </ASP: scriptmanager>
<SCRIPT type = "text/JavaScript">
SYS. webforms. pagerequestmanager. getinstance (). add_pageloading (
Function (sender, E)
...{
VaR dataitem = E. get_dataitems () ["<% = This. updatepanel1.clientid %>"] ();
Alert (dataitem. Name );
});
</SCRIPT>
<Div>
<Asp: updatepanel id = "updatepanel1" runat = "server">
<Contenttemplate>
<Asp: button id = "test" runat = "server" text = "test" onclick = "test_click"/>
</Contenttemplate>
</ASP: updatepanel>
</Div>

</Form>
</Body>
</Html>
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;

Using system. Web. Script. serialization;

Public partial class webform1: system. Web. UI. Page
...{
Protected void page_load (Object sender, eventargs E)
...{

}

Protected void test_click (Object sender, eventargs E)
...{
Javascriptserializer serializer = new javascriptserializer ();
Scriptmanager. getcurrent (this. Page). registerdataitem (this. updatepanel1, "VaR _ f = function () {alert ('Hello world! ');}; _ F; ", true );

}

}



(3) Use Javascript Non-Modal Dialog Box prompts Eg.Page. registerstartupscript ("alert", "<script language = 'javascript '> Window. showmodelessdialog(\ "Javascript: Alert ('failed to cancel the reporting operation. Please check the subject to be handed in! '); Window. close (); \ ", \" \ ", \" status: No; resizable: No; help: No; dialogheight: Height: 30px; dialogheight: 40px ;\") </SCRIPT> ");
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.