Various JavaScript scripts

Source: Internet
Author: User

1. How to control the checkbox Selection in datalist cannot exceed 3
. CS
Private void datalistpolicitemdatabound (Object sender, system. Web. UI. webcontrols. datalistitemeventargs E)
{
Checkbox cbx = (checkbox) E. Item. findcontrol ("checkbox1 ");
Cbx. Attributes. Add ("onclick", "checkit (this )");
}

. Aspx

<Script language = JavaScript>
VaR num = 0;
Function checkit (OBJ ){
If (obj. Checked ){
Num ++;
} Else {
Num --;
}
If (Num> 3 ){
Num --;
OBJ. Checked = false;
Alert ("no more than three! ");
}
}
</SCRIPT>

2. Delete selected rows from datalist
<Itemtemplate>
<Span style = "cursor: Hand" id = "span <% # (messaging. dataprovider. messagerecord) getdataitem ()). id %> "onclick =" deletemessge (<% # (messaging. dataprovider. messagerecord) getdataitem ()). id %>, this) "> Delete </span> <a href =" reply. aspx? Originchatto = <% # (messaging. dataprovider. messagerecord) getdataitem ()). chatto %> "style =" text-Decoration: none; color: #666666; "target =" _ blank "> reply </a>

<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function deletemessge (theid, thisobj)
{
Window. Confirm ("are you sure you want to delete this message? ");
Inbox. deletemessage (theid); // Ajax does not need to be deleted
Thisobj. parentelement. parentelement. removenode (true );
}
</SCRIPT>
</Itemtemplate>
3. When the user clicks the close button of the browser, a prompt is displayed before the browser is closed (the content on the current browser page can be viewed) to remind the user that there may be unsaved data.
Function window. onbeforeunload ()
{
If (event. clientx> 360 & event. clienty <0 | event. altkey)
{
Window. event. returnvalue = "";
}
}
4. you have added a pop-up dialog box attribute to the delete button. Can you bring up a different dialog box based on the user login situation: the content of the Unlogged user dialog box is "no permission", and the login user is "Delete "!
Front-end JS

function gocheck (type)
{< br> If (type = 0)
{< br> alert ("no permission"); Return false;
}< br> else return confirm ("Delete! ");
}< br> background. CS
int I;
If (SUID =" "| SUID = NULL | SUID! = UID) {I = 0 ;}< br> else {I = 1 ;}< br> btn_del.attributes.add ("onclick", "Return gocheck_del (" + I. tostring () + ");");
btn_modify.attributes.add ("onclick", "Return gocheck_mod (" + I. tostring () + ");");

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.