C # Call the frontend page js method in the background

Source: Internet
Author: User

Http://www.cnblogs.com/weiying/archive/2011/09/28/weiyinghhghhhh.html

I will share this log with you in my opinion:

 

Original article address: C # frontend page calling js method: Author: wuyawei4062

1. C # Call the js method on the front-end page in the background:

Clientscriptmanager cs = page. clientscript;
CS. registerstartupscript (this. GetType (), "", "<SCRIPT type = \" text/JavaScript \ "> subjectlistener (); </SCRIPT> ");

2. C # How to refresh the parent page of a new page:

2.1 now we have a main framework page. Now we have a list of all the details on this page. When we click a list, we can view its details, when we click Modify, We can modify a message. When we click Modify, we open a new one. After the modification, click OK. We will close the current modification page and return to the Information List page, in addition, we need to refresh the current modification information in a timely manner. Here, we can close the current page when the modification is successful and then call the JS on the parent framework page, put a button on the page and set its height and width to 0px. We will write part of the code to be refreshed in its on_click event. Next, we will analyze it step by step:

<Asp: hyperlink id = "hlupdate" text = "modify" navigateurl = '<% # "updateschool. aspx? Shoolid = "+ eval (" shoolid ") +" "%> 'target =" _ blank "runat =" server ">

We now have a link to modify the list information page. When we click Modify, we want to open the new page, updateschool. aspx. After modifying this information on the modification page, click OK. If the modification is successful, we will close the current modification page and return to the List page to confirm that the modification is successful:

// Give a prompt and refresh the parent page
System. Text. stringbuilder strjs = new system. Text. stringbuilder ();
Strjs. append ("try {window. opener. submitform () ;}catch (Ex ){}");
Strjs. append ("alert ('Modified successfully'); window. opener = NULL; window. open ('', '_ Self'); window. close ();");
Clientscript. registerstartupscript (this. GetType (), "", strjs. tostring (), true );

Analyze this code. When the modification is successful, the system prompts that the modification is successful, closes the current page, and then calls the JS submitform (); method of the parent page.

Function submitform (){
VaR OBJ = Document. getelementbyid ("btreload ");
OBJ. Click ();
}

<Asp: button id = "btreload" width = "0" Height = "0" runat = "server" onclick = "btreload_click"/>

Background implementation:

/* Perform this operation when refresh the parent page by sending a response */
Protected void btreload_click (Object sender, eventargs E)
{
String sqlstring = viewstate ["where"]. tostring () + viewstate ["orderby"]. tostring ();
Bindeditionlist (aspnetpager1.currentpageindex, sqlstring); // when you click back on that page
}

Here, I will analyze the main task here: When you successfully submit the modification page to this page, the page will automatically call the on_click event to refresh the page.

This is OK. The summary is as follows:

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.