In the updatepanel dialog box in Ajax, you can use:
Scriptmanager. registerstartupscript (updatepanel1, this. GetType (), "alert", "alert ('Update successful! ') ", True );
When you jump to another page after modification, you can use:
Scriptmanager. registerstartupscript (updatepanel1, this. GetType (), "click", "location. Replace ('usermanger. aspx ');", true );
If there is a prompt before the jump, you can use:
Scriptmanager. registerstartupscript (this. Page, this. GetType (), "click", "alert ('Update successful! '); Location. Replace ('usermanger. aspx'); ", true );
For example, scriptmanager. registerstartupscript (this. updatepanel1, this. GetType (), "prompt", "alert ('shopping cart is empty, please shop first! ') ", True );
Protected void updatepanelalert (string str_message)
{
Scriptmanager. registerstartupscript (this. updatepanel1, this. GetType (), "prompt", "alert ('" + str_message + "')", true );
}
Updatepanelalert ("No such code ");
//////////////////////////////////////// //////////////////////////////////////// /////////////
Asp.net Ajax framework updatepanel pop-up tips
<Asp: updatepanel runat = "server" id = "p1">
*. CS:
Microsoft. Web. UI. scriptmanager. registerstartupscript (P1, this. GetType (), "click", "alert ('OK')", true );
Response. Write ("") cannot be used in updatepanel of ASP. NET. It is not very convenient.
Use the updatepanel-supported method!
This. clientscript. registerclientscriptblock (this. GetType (), "A", "alert ('OK! '); ", True );
For 1.0.
Scriptmanager. registerstartupscript (this. Page, this. GetType (), "click", "alert ('OK')", true );
System. Web. UI. scriptmanager. registerstartupscript (button1, this. GetType (), "click", "alert ('OK')", true );
About updatepanel registration and execution of JavaScript
I 've been confused for a few days, and I 've been lazy recently. I saw a message and never updated my blog's first prize. It's quite embarrassing, haha. Write down some minor problems that you or others have encountered recently.
1. About registering JS with updatepanel
I recently used ALTAS in my project. I am also a newbie, and I am still using the simplest updatepanel. I have encountered difficulties in registering scripts and cannot register ALTAS. I originally put a gridview in updatepanel. I even want to click a form in a template column in girdview and register window. open () to solve the problem. It is not in updatepanel, so it is easy to directly register with clientscript. registerstartupscript.
After you drag the updatepanel file, you will find that you cannot register the script. Think about registerstartupscript, which was originally used to start JS when loading the page. If you partially refresh the updatepanel file, you cannot register it.
Later, I found the scriptmanager. registerstartupscript method, which is quite good.
Scriptmanager. registerclientscriptblock (updatepanelname, typeof (updatepanel), "ID key", "script", true );
The following is a demo. The template column is defined as follows:
<Asp: templatefield headertext = "Customer ID">
<Itemtemplate>
<Asp: linkbutton id = "linkbtncid" runat = "server" text = '<% # eval ("CID") %> 'commandname = "linkbtncid"> </ASP: linkbutton>
</Itemtemplate>
</ASP: templatefield>
In the rowcommand event corresponding to the gridview, perform the following operations:
Protected void gvclientinfo_rowcommand (Object sender, gridviewcommandeventargs E)
{
// If a linkbutton is clicked
If (E. commandname. Equals ("linkbtncid "))
{
Linkbutton lbtn = (linkbutton) E. commandsource;
Gridviewrow dgrow = (gridviewrow) lbtn. Parent. parent;
String tmptext = lbtn. Text. tostring ();
Tmptext = "window. Open ('mermerdetailsinfo. aspx? Cid = "+ tmptext +" ', 'newwindow', 'height = 550,
Width = 700, menubar = no ')";
Scriptmanager. registerstartupscript (this. updatepanel2, this. GetType (), "click", tmptext, true );
}
}
2. About registerstartupscript and registerclientscriptblock
Registerstartupscript embeds JS at the bottom of the page.
Registerclientscriptblock embeds JS into the page. After enabling the element <form>
3. "This row already belongs to another table" error
This is a problem with row replication between different datatables.
Check this Code:
Datatable tmpdt = sodo. getdatatable ("text", strsql, SP );
DT. Rows. Add (tmpdt. Rows [0]);
This obvious error is that the tmpdt row is an object reference, which is equivalent to a pointer. errors are inevitable. The following solutions are available:
Datatable tmpdt = sodo. getdatatable ("text", strsql, SP );
1. dt. Rows. Add (tmpdt. Rows [0]. itemarray );
2. dt. importrow (tmpdt. Rows [0]);
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/Lijinlin/archive/2010/11/02/5981138.aspx