How do you validate a textbox when a checkbox is checked in a RadGrid using JavaScript? I tried to use the CheckBox_CheckedChanged event but it is not working. Please tell me how to validate if the textbox is empty or not when a checkbox is checked in a RadGrid in ASP.NET.
C#:
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
foreach (GridDataItem item in radGridSahreaJob.MasterTableView.Items)
{
TextBox txtMaxResumes = (TextBox)item.FindControl("txtMaxResumes");
CheckBox chkBox = (CheckBox)item.FindControl("chkIsCandidateSelected");
string str = txtMaxResumes.Text;
if (chkBox.Checked && string.IsNullOrEmpty(str))
{
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "alert", "getMessagetest('ShareaJob');", true);
}
}
}
ASP.NET:
<Columns>
<telerik:GridTemplateColumn UniqueName="chkSelect" lowFiltering="false">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" OnClick="return SelectAllCandidates(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkIsCandidateSelected" runat="server" OnClick="return CandidateRowChecked();" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged1"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Max.Resume(s) can upload" HeaderStyle-HorizontalAlign="Center" ShowFilterIcon="false" AllowFiltering="false">
<ItemTemplate>
<asp:TextBox ID="txtMaxResumes" runat="server" CssClass="rgf_txt_area_l2" Text="3" Width="80px" MaxLength="2">
</asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
JavaScript:
function getMessagetest(entity) {
if (entity == 'ShareaJob') {
radalert("Please enter number !", 370, 150, "Alert");
}
}
finally i got solution. Thanks.
foreach (GridDataItem item in radGridSahreaJob.MasterTableView.Items)
{
CheckBox CheckBox1 = item.FindControl("chkIsCandidateSelected") as CheckBox;
TextBox TextBox1 = item.FindControl("txtMaxResumes") as TextBox;
string strTxtResumes = TextBox1.Text;
if (CheckBox1 != null && CheckBox1.Checked && string.IsNullOrEmpty(strTxtResumes))
{
hdnCheckBox.Value = "1";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.