Greetings exerts and happy new year to all of you.
We have a tricky situation that I hope you can help resolve for me.
We have a gridview with control ID="grvspouse".
This gridview has two textboxes, one for name (txtspousename) and the other for address (spouseaddress).
Our requirement are as follows:
1, If txtspousename is not blank, then spouseaddress cannot be blank
2, if both txtspousename and spouseaddress are not blank, then check control (spouseDetails) to be automatically disabled.
3, If user wants to leave both txtspousename and spouseaddress blank, then user must check the spouseDetails checkbox.
We believe numbers 1 through 3 works as intended.
Here is where we are having problem.
If user enters value into txtspousename and spouseaddress boxes and realizes it was a mistake and decides to remove those values, the user cannot.
The reason the user cannot remove them is because they are grayed out (disabled) and since they are disabled, the checkbox based on requirement, is also disabled because there is value in both txtspousename and spouseaddress.
My question is this, how do I make sure that if user enters data into both textboxes and decides to remove, what do I need to change in the two methods below to ensure that this is possible?
I hope my issue is explained clearly.
HTML
<asp:GridView ID="grvspouse" RowStyle-Wrap="false" GridLines="None" CssClass="responsiveTable1"
runat="server" ShowFooter="true" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="SpouseNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Name">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:TextBox ID="txtspousename" Text='<%# Eval("spousename") %>' placeholder="Name...(e.g, Jane Doe)"
runat="server" Style="width: 375px;" class="form-control" AutoPostBack="true"
OnTextChanged="txtspousename_TextChanged"></asp:TextBox><br />
<asp:CheckBox ID="spouseDetails" ClientIDMode="Static" runat="server" Checked="false"
AutoPostBack="true" OnCheckedChanged="SpouseCheckChanged" /><span style="color: #ff0000">*Check
this box if N/A</span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemStyle HorizontalAlign="Left"></ItemStyle>
<ItemTemplate>
<asp:TextBox ID="txtspouseaddress" Text='<%# Eval("spouseaddress") %>' placeholder="Address..."
runat="server" Style="width: 375px;" class="form-control"></asp:TextBox><br />
<br />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code
Protected Sub txtspousename_TextChanged(sender As Object, e As EventArgs)
For Each row As GridViewRow In grvspouse.Rows
Dim spousename As TextBox = TryCast(row.FindControl("txtspousename"), TextBox)
Dim spouseSelect As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox)
If spousename.Text.Length > 0 Then spouseSelect.Enabled = False Else spouseSelect.Enabled = True
Next
End Sub
Protected Sub SpouseCheckChanged(ByVal sender As Object, ByVal e As EventArgs)
For Each row As GridViewRow In grvspouse.Rows
Dim spousename As TextBox = TryCast(row.FindControl("txtspousename"), TextBox)
Dim spouseaddress As TextBox = TryCast(row.FindControl("txtspouseaddress"), TextBox)
Dim spouseSelect As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox)
If Not spouseSelect.Checked Then
spousename.Enabled = True
spouseaddress.Enabled = True
Else
spousename.Enabled = False
spouseaddress.Enabled = False
End If
Next
End Sub
Thank you in advance