Recently encountered some problems, with a layer hint message box, such as delete, when the message is determined to return false, then no matter, because the layer does not support blocking, the following to solve the problem:
To delete a button code:
<asp:button id="Btndel"Name="Btndel"runat="Server"text="Delete" class="btn Btn-gray"onclientclick="return Resdel ();"onclick="Btndel_click"Usesubmitbehavior="false"/>
Note Add property usesubmitbehavior= "False" This property must be added so that the Delete button is manually submitted the basic idea is: write a function to close the layer.confirm ();
Parameter description: MSG is the message content, Eventtarget for the control to submit to the background event Name,eventargument as a submit parameter, empty when there is no parameter.
1 function Layerconfirm (msg, Eventtarget, eventargument) {2 layer.confirm (msg, function ( Index) {3 __dopostback (Eventtarget, eventargument); 4 5 }); 6 7 }
The following is a detailed analysis:
JS Code:
<script type="text/javascript"> function Resdel () { layer.confirm ( " Are you sure you want to delete it?" ", Function (index) { __dopostback ('btndel') 1'); }); } </script>
Background Delete button event code:
1 /// <summary>2 ///Delete button Events3 /// </summary>4 /// <param name= "Sender" ></param>5 /// <param name= "E" ></param>6 protected voidBtndel_click (Objectsender, EventArgs e)7 {8 string Select= Crequest.getstring ("Selectid");9 if(Select. Trim () = ="")Ten { OneJscript.alert ("you do not have the data selected!", This. Page); A return; - } - if(_user. Departmenttypeid = = (int) Admindepartmenttypeenums.manager | |_user. Isgroupleader) the { -Friendlylink.deleteall (string. Format ("Id in ({0})",Select)); -Jscript.alertandredirect ("Delete Success! ", This. Request.rawurl); - } + Else - { +Jscript.alert ("you do not have permission to delete! ", This. Page); A return; at } -}
At this point also to add a callback in the Page_Load statement (code below):
1 stringControlName = Request.Params.Get ("__eventtarget");//Eventtarget is the control to be submitted to the background event name2 stringeventargument = Request.Params.Get ("__eventargument");//Use this parameter to determine whether the button is clicked (parameter values can be arbitrarily written)3 if(ControlName = ="Btndel"&& eventargument = ="1")//determine whether two parameters satisfy the corresponding data, and invoke the event if satisfied4 {5 Btndel_click (sender, E);6}
At this point the execution will find
Page report this error
. NET based on the output elements in the page generates a __eventvalidation hidden field in the final page. Did a simple test. Page, create a <asp:button id= "btnsubmit" runat= "Server" text= "submit" tooltip= "Submit"/>, while creating the corresponding click event handler. Run the program to respond correctly to events. Then set Btnsubmit.visable=false, manually add <input type= "Submit" Name= "Btnsubmit" value= "submit"/> on the page. When you run the program, an exception that contains enableeventvalidation content appears. Set < @Page enableeventvalidation= "false" > Run the program again and respond correctly to the event. Observe the contents of the __eventvalidation two times before and after observation, can be found to be different. Regarding the occurrence of the exception, it can be thought that the output is not included in the Btnsubmit, but then submitted to the background when there is the corresponding content, inconsistent, so in the case of an open event check. NET throws an exception.
Page_Load (object sender, EventArgs e)
{
if (! Page.IsPostBack)
{
binding data;
}
}
In the page head <% @Page ....%> add enableeventvalidation= "false" this time to execute, the page has been able to normal layer hints and deleted, hope will help you. PS: Write in a hurry, have any comments and suggestions of the hope reply, I will correct the error, solve the problem.
Layer implementation confirm popup before foreground delete and callback background Delete event