asp中的Javascript函数:多视图+;asp.向导
我有一个asp.net页面asp中的Javascript函数:多视图+;asp.向导,javascript,asp.net,Javascript,Asp.net,我有一个asp.net页面包含asp:MultiView和asp:Wizard ID=“wizardIscrizione两个文本框(ID=txtNome1、txtCognome1、txtNome2、txtCognome2等等)。一半的文本框在向导步骤1中,另一半在向导步骤2中。 我的javascript函数设置为onchange textbox事件 <script type="text/javascript"> function CalcolaJs() {
包含asp:MultiView
和asp:Wizard ID=“wizardIscrizione
两个文本框(ID=txtNome1、txtCognome1、txtNome2、txtCognome2等等)。
一半的文本框在向导步骤1中,另一半在向导步骤2中。 我的javascript函数设置为onchange textbox事件
<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>
你能发布aspx视图控件源代码吗?代码中没有什么可疑之处,但为什么要使用此代码“else contaiscriti=contaiscriti;“添加完成,谢谢。你是对的:不需要else块。你可以在html源代码上检查你的输入id。如果输入id的前缀不是错误,但不是精细输入,那么这就是javascript问题。你需要firefox firebug。你能指出导致问题或无法工作的textbox的id吗?请尝试设置textbox ClientMode=static的属性的第一件事然后,一旦改变了textbox,运行javascript函数,比如functextchange(this);如果它不起作用,请告诉我
<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;
}