У меня есть две страницы. На первой странице у меня есть button1
, и когда я нажимаю на это сообщение sessions
на следующие страницы и redirect
на вторую страницу. На второй странице у меня есть RequiredFieldValidators
, но когда я нажимаю button1
, покажи мне такую ошибку!Ошибка RequiredFieldValidator в моем asp.net
Server Error in '/' Application.
The ControlToValidate property of 'FirstnameRequiredFieldValidator' cannot be blank.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The ControlToValidate property of 'FirstnameRequiredFieldValidator' cannot be blank.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The ControlToValidate property of 'FirstnameRequiredFieldValidator' cannot be blank.]
System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +9831920
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +36
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Моя вторая кодовая страница:
<table style="width:100%;">
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server" Text="نام" Font-Size="Larger"></asp:Label>
</td>
<td class="auto-style2">
<asp:TextBox ID="firstnametxt" runat="server" Height="22px" MaxLength="20"
Width="158px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="FirstnameRequiredFieldValidator" runat="server" ForeColor="Red" ErrorMessage="نام خود را وارد کنید"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="نام خانوادگی" Font-Size="Larger"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="lastnametxt" runat="server" Height="22px" MaxLength="10"
Width="158px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="LastbaneRequiredFieldValidator" runat="server" ForeColor="Red" ErrorMessage="نام خانوادگی خود را وارد کنید."></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="شماره تلفن" Font-Size="Larger"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="phonetxt" runat="server" Height="22px" MaxLength="10"
Width="158px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="PhoneRequiredFieldValidator" runat="server" ForeColor="Red" ErrorMessage="شماره تلفن خود را وارد کنید."></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="Phonevalidator"
runat="server" ForeColor="Red" ControlToValidate="phonetxt"
ErrorMessage="شماره وارد شده نامعتبر است ."
ValidationExpression="\d+">
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
<asp:Button ID="buy" runat="server" onclick="buybtn_Click" Text="Submit" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style2">
<td><asp:Label ID="msglabel" runat="server" ></asp:Label></td>
</td>
<td>
</td>
</tr>
</table>
Мой код кнопки:
protected void button1_Click(object sender, EventArgs e)
{
Session["Numofclass"] = Numofclass.SelectedItem.Value;
Session["totalprice"] = totalprice;
Session["Numofstud"] = Numofstud.SelectedItem.Value;
Response.Redirect("account.aspx");
}
Мой первый код страницы:
.
.
.
<section class =" container">
<!-- start Pages -->
<div id="pages">
<div class="top_shadow"></div>
<!-- Start Price -->
<div id="price" class="page">
<h1>برنامه ریزی کلاس مجازی و قیمت</h1>
<div class="tabs">
<div id="tab_1" class="pane" style="width:85%;text-align:center">
<p style="text-align:right;border-bottom:1px solid #aaa">برخی اساتید و معلمانی هستند که میخواهند آموزش خود را گسترش دهند اما نیاز به فضا و تجهیزاتی دارند که آنها را از این کار باز میدارد. با ارتقا عضویت خود در طرح دبیرانه به همه امکانات لازم برای گسترش بدون مرز آموزش خود با همه امکانات و تجهیزات لازم دست پیدا میکنید.</p>
<form id="price_biz_calculator"><input type="hidden" name="biz"/>
<p>تعداد نفرات دانشجویان شما:
<asp:DropDownList ID="Numofstud" runat="server" AutoPostBack="True" Height="40px" OnSelectedIndexChanged="Numofstud_SelectedIndexChanged" Width="150px">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>200</asp:ListItem>
<asp:ListItem>250</asp:ListItem>
</asp:DropDownList>
</p>
<p>تعداد کلاس‌های همزمان:     
<asp:DropDownList ID="Numofclass" runat="server" AutoPostBack="True" Height="40px" style="margin-left: 0px" Width="150px" OnSelectedIndexChanged="Numofclass_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
</asp:DropDownList>
</p>
</form>
 
 
<p id="price_final_biz" style="color:#6b6b6b;font-size:100px;line-height:90px"></p>
<span style="font-size:20px;vertical-align:22%">ماهیانه</span>
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server" ViewStateMode="Inherit" ValidateRequestMode="Inherit"></asp:ScriptManager>
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTotalprice" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="Numofclass" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger controlid="Numofstud" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<span style="font-size:20px;vertical-align:22%">هزار تومان</span>
 
 
<div>
<td>
<asp:Button ID="button1" runat="server" onclick="button1_Click"
Text="ثبت" Height="34px" Width="81px" />
</td>
</div>
</div>
</div>
<!-- End Price -->
<div class="bottom_shadow"></div>
</div>
</div>
<!-- End Pages -->
<div class="clear"></div>
<!-- End Pages -->
</section>
спасибо, что сейчас работает –