我有一个 asp.net 页面
,其中包含 asp:MultiView
,其中包含 asp:View 和一个 asp:Wizard ID="wizardIscrizione
,其中包含 20 个文本框。(ID= txtNome1、txtCognome1、txtNome2、txtCognome2 等等)。
一半的文本框在向导 Step1 中,另一半在向导 Step2 中。我的 javascript 函数设置为 onchange 文本框事件。
<script type="text/javascript">
function CalcolaJs() {
var contaIscritti = 0;
for (var i = 1; i < 11; i++) {
var conta = (i).toString();
var nome = document.getElementById('wizardIscrizione_' + 'txtNome' + conta).value;
var cognome = document.getElementById('wizardIscrizione_' + 'txtCognome' + conta).value;
if (((nome != "") && (nome !== null) && (nome !== undefined)) &&
((cognome != "") && (cognome !== null) && (cognome !== undefined)))
contaIscritti = contaIscritti + 1;
else contaIscritti = contaIscritti;
document.getElementById('hidNumPartecipanti').value = contaIscritti;
document.getElementById('lblNumPartecipanti').innerHTML = contaIscritti;}
}
}
</script>
Javascript 函数适用于向导第 1 步中的文本框,但在第 2 步中却不行。我真的不知道为什么!编辑:asp.net 来源:
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="VistaIscrizione" runat="server">
<asp:Wizard ID="wizardIscrizione" runat="server" ActiveStepIndex="0" CancelButtonStyle-CssClass="button" FinishCompleteButtonStyle-CssClass="button" FinishPreviousButtonStyle-CssClass="button" NavigationButtonStyle-CssClass="button" FinishCompleteButtonText="Conferma" StartNextButtonText="Avanti >>" StepNextButtonText="Avanti >>" StepPreviousButtonText="<< Indietro" OnFinishButtonClick="wizardIscrizione_FinishButtonClick" DisplaySideBar="False" Width="100%" OnActiveStepChanged="wizardIscrizione_ActiveStepChanged">
<WizardSteps>
<asp:WizardStep ID="StepPartecipanti1" runat="server" Title="Step 1 di 3 - Inserisci il nominativo dei partecipanti">
<fieldset class="gradientCoolBlack">
<legend></legend>
<p class="titoloStep">Nominativo dei Partecipanti</p>
<p><asp:Label ID="Label14" runat="server" CssClass="label">? Nome e Cognome:</asp:Label></p>
<p>
<asp:Label ID="Label15" runat="server" CssClass="label" Width="20px" Text=" 1. " />
<asp:RequiredFieldValidator ID="r001" runat="server" ControlToValidate="txtNome1" />
<asp:RequiredFieldValidator ID="r002" runat="server" ControlToValidate="txtCognome1" />
<asp:TextBox ID="txtNome1" runat="server" CssClass="input" Width="250px" MaxLength="15"/>
<asp:TextBox ID="txtCognome1" runat="server" CssClass="input" Width="250px" MaxLength="15"/>
</p>
<p>
<asp:Label ID="Label16" runat="server" CssClass="label" Width="20px" Text=" 2. " />
<asp:RequiredFieldValidator ID="r18" runat="server" ControlToValidate="txtNome2" />
<asp:RequiredFieldValidator ID="r19" runat="server" ControlToValidate="txtCognome2" />
<asp:TextBox ID="txtNome2" runat="server" CssClass="input" Width="250px" MaxLength="15" />
<asp:TextBox ID="txtCognome2" runat="server" CssClass="input" Width="250px" MaxLength="15" />
</p>
<p>
<asp:Label ID="Label17" runat="server" CssClass="label" Width="20px" Text=" 3. " />
<asp:RequiredFieldValidator ID="r16" runat="server" ControlToValidate="txtNome3" />
<asp:RequiredFieldValidator ID="r17" runat="server" ControlToValidate="txtCognome3" />
<asp:TextBox ID="txtNome3" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome3" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label181" runat="server" CssClass="label" Width="20px" Text=" 4. " />
<asp:RequiredFieldValidator ID="r22" runat="server" ControlToValidate="txtNome4" />
<asp:RequiredFieldValidator ID="r23" runat="server" ControlToValidate="txtCognome4" />
<asp:TextBox ID="txtNome4" runat="server" CssClass="input" Width="250px" MaxLength="15" ></asp:TextBox>
<asp:TextBox ID="txtCognome4" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label19" runat="server" CssClass="label" Width="20px" Text=" 5. " />
<asp:RequiredFieldValidator ID="r20" runat="server" ControlToValidate="txtNome5" />
<asp:RequiredFieldValidator ID="r21" runat="server" ControlToValidate="txtCognome5" />
<asp:TextBox ID="txtNome5" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome5" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<span style="color: White">Altri Partecipanti</span>
<asp:CheckBox ID="chkAltri" runat="server" AutoPostBack="True" OnCheckedChanged="chkAltri_CheckedChanged" />
<asp:TextBox ID="txtCounter" runat="server" Height="16px" Width="40px"></asp:TextBox>
</p>
<p>
</p>
</fieldset>
</asp:WizardStep>
<asp:WizardStep ID="StepPartecipanti2" runat="server" Title="Step 1 di 3 - Inserisci il nominativo dei partecipanti">
<fieldset class="gradientCoolBlack">
<legend></legend>
<p style="text-align: right; font-size: 18px; font-family: Candara; color: #17ef1f">
Nominativo dei Partecipanti</p>
<p>
<asp:Label ID="Label10" runat="server" CssClass="label">? Nome e Cognome:</asp:Label>
</p>
<p>
<asp:Label ID="Label21" runat="server" CssClass="label" Width="20px" Text=" 6. " />
<asp:RequiredFieldValidator ID="r24" runat="server" ControlToValidate="txtNome6"/>
<asp:RequiredFieldValidator ID="r25" runat="server" ControlToValidate="txtCognome6"/>
<asp:TextBox ID="txtNome6" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome6" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label121" runat="server" CssClass="label" Width="20px" Text=" 7. " />
<asp:TextBox ID="txtNome7" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome7" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label12" runat="server" CssClass="label" Width="20px" Text=" 8. " />
<asp:TextBox ID="txtNome8" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome8" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label11" runat="server" CssClass="label" Width="20px" Text=" 9. " />
<asp:TextBox ID="txtNome9" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome9" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label13" runat="server" CssClass="label" Width="20px" Text="10. " />
<asp:TextBox ID="txtNome10" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
<asp:TextBox ID="txtCognome10" runat="server" CssClass="input" Width="250px" MaxLength="15"></asp:TextBox>
</p>
<p>
</p>
</fieldset>
</asp:WizardStep>
</asp:MultiView>
代码隐藏:
protected void Page_Load(object sender,EventArgs e)
{
AddOnChangeAttribute(Page);//Add .Attributes.Add("onchange","CalcolaIscrittiJs()") to txtNome(i) and txtCognome(i);
numeroPartecipanti = Convert.ToInt16(HttpUtility.HtmlEncode(Page.Request.Form["hidNumPartecipanti"]));
hidNumPartecipanti.Value = numeroPartecipanti.ToString();//valore pagina 2
lblNumPartecipanti.Text = hidNumPartecipanti.Value;
}