我有一个带有 "Id "的文本框 "txtCertificate"。我想在C#中抓取该值,并放入一个条件,如果 "txtCertificate "的值为空,我想显示一个警告信息。我怎样才能做到这一点?
<tr>
<td style="padding-top: 5px; width: 150px;">Document Title:</td>
<td style="padding-top: 5px;">
<table border="0">
<tr>
<td>
<telerik:RadTextBox ID="txtCertificate" runat="server" ValidationGroup="vgCertificate" Width="361px" MaxLength="50" ClientIDMode="AutoID"
Text='<%# DataBinder.Eval( Container, "DataItem.Certification" ) %>'>
</telerik:RadTextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCertificate" runat="server" ControlToValidate="txtCertificate"
ErrorMessage="Title is Required" ForeColor="#CC0000" ValidationGroup="vgCertificate">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
<td style="padding-top: 5px;"></td>
</tr>
我试着用这种方式来抓取值并尝试比较。
var documentTitle = $find("<%# txtCertificate.ClientID %>");
var documentTitleText = documentTitle.value();
if (documentTitleText == null)
{
alert("Test");
preventDefault();
return false;
}
else
{
return true;
}`
这个对我来说是可行的。
var documentTitle = $find("<%# txtCertificate.ClientID %>");
var documentTitleText = documentTitle.get_value();
if (documentTitleText == null || documentTitleText =="") {
alert("test");
preventDefault();
return false;
}
else {
return true;
}