Mentre attendo come consigliato da Andrea, qualche passo avanti...
La convalida secondo condizioni previste adesso funziona, quello che non riesco a fare è nella funzione javascript far visualizzare una alert quando i campi del form sono lasciati vuoti...![]()
codice:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="button.aspx.cs" Inherits="SqlServer_button" %> <!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 id="Head1" runat="server"> <title></title> </head> <body onload="InitValidators()"> <form id="form1" runat="server"> ... <asp:TextBox ID="DateStart" runat="server"></asp:TextBox> <asp:TextBox ID="DateEnd" runat="server"></asp:TextBox> ... <asp:ImageButton ID="Button1" ImageUrl="images/cerca_icon.gif" runat="server" OnClick="Button1_Click" OnClientClick="javascript:return InitValidators();return false;" /> ... <asp:TextBox ID="DateStart1" runat="server"></asp:TextBox> <asp:TextBox ID="DateEnd1" runat="server"></asp:TextBox> ... <asp:ImageButton ID="Button2" ImageUrl="images/cerca_icon.gif" runat="server" OnClick="Button2_Click" OnClientClick="javascript:return InitValidators();return false;" /> ... </form> <script type="text/javascript" language="javascript"> function InitValidators() { var DateStart = document.getElementById('<%=DateStart.ClientID%>'); var DateEnd = document.getElementById('<%=DateEnd.ClientID%>') var DateStart1 = document.getElementById('<%=DateStart1.ClientID%>'); var DateEnd1 = document.getElementById('<%=DateEnd1.ClientID%>') if (DateStart.value == '' || DateEnd.value == '') { ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), true); ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), true); } else { ValidatorEnable(document.getElementById('<%= RequiredFieldValidator1.ClientID%>'), false); ValidatorEnable(document.getElementById('<%= RequiredFieldValidator2.ClientID%>'), false); } if (DateStart1.value == '' || DateEnd1.value == '') { ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), true); ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), true); } else { ValidatorEnable(document.getElementById('<%= RequiredFieldValidator3.ClientID%>'), false); ValidatorEnable(document.getElementById('<%= RequiredFieldValidator4.ClientID%>'), false); } } </script> </body> </html>

Rispondi quotando