Click here to Skip to main content
14,644,810 members
Home » Discussions » ASP.NET
   

ASP.NET

 
Questionint retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Lay_Kay21-Dec-17 3:39
MemberLay_Kay21-Dec-17 3:39 
AnswerRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
David Mujica21-Dec-17 4:54
MemberDavid Mujica21-Dec-17 4:54 
GeneralRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Lay_Kay21-Dec-17 17:50
MemberLay_Kay21-Dec-17 17:50 
SuggestionRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Richard Deeming22-Dec-17 2:08
mveRichard Deeming22-Dec-17 2:08 
AnswerRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Richard Deeming22-Dec-17 2:11
mveRichard Deeming22-Dec-17 2:11 
GeneralRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Lay_Kay22-Dec-17 5:19
MemberLay_Kay22-Dec-17 5:19 
AnswerRe: int retryattempts = Convert.ToInt32(dr["retryattempts"]); Pin
Richard MacCutchan21-Dec-17 5:18
mveRichard MacCutchan21-Dec-17 5:18 
QuestionHow to ensure user either checks a box or fills out the form? Pin
samflex18-Dec-17 7:48
Membersamflex18-Dec-17 7:48 
Greetings again,

I am really struggling to get my code to work.

have a gridview with ID = Gridview1.

This gridview has three textboxes and one checkbox with id = grid1Details

The requirements:


if => checkbox is unchecked and textboxes are empty => You cannot submit your form

if => checkbox is checked and textboxes are empty => You can submit your form

if => checkbox is unchecked and textboxes are not empty => You can submit your form

By default, upon page load, checkbox is unchecked and textboxes are enabled.

How do I modify the following code to make this work?

Protected Sub Grid1CheckChanged(ByVal sender As Object, ByVal e As EventArgs)
     'Dim hasBlank As Boolean = False
     For Each row As GridViewRow In Gridview1.Rows
         Dim ename As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox)
         Dim empaddress As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox)
         Dim empincomesrc As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox)
         Dim sourceCheck As CheckBox = DirectCast(Gridview1.FindControl("grid1Details"), CheckBox)
         If Not sourceCheck.Checked Then
             'hasBlank = True
             ename.Enabled = True
             empaddress.Enabled = True
             empincomesrc.Enabled = True
         ElseIf Not sourceCheck.Checked And ename.Text Is Nothing And empaddress.Text Is Nothing And empincomesrc.Text Is Nothing Then
             lblStatus.Text = "Please either fill out the textboxes or check the checkbox."
         Else
             ename.Enabled = False
             empaddress.Enabled = False
             empincomesrc.Enabled = False
         End If
     Next
 End Sub



JavaScript would probably be better but my attempt at using JavaScript has not worked so far.

Below is my attempt at javascript:

<script type="text/javascript">

    function ValidateTextBox() {
        checkbox = document.getElementById("grid1Details");
        var textvalue = $(".textClass").attr('value');
        if (!checkbox.checked &&  textvalue != "") {
                alert("Either check the box or enter value in all textboxes.");
                return false;
            }
            return true;
        }

</script>


//markup:
<td> <asp:Button ID="btnNext" CssClass="btnNext" runat="server" Text="Review Form" OnClientClick="BtnClick();javascript:return ValidateTextBox();" OnClick="btnNext_Click" /></td>

   <table>
    <tr>
        <td>
          <asp:gridview ID="Gridview1" gridlines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting">
            <Columns>
            <asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
            <asp:TemplateField HeaderText="Name">
             <headerstyle horizontalalign="Left" />
                <ItemTemplate>
                    <asp:TextBox ID="txtsourcename" CssClass="textClass" placeholder="Name...(e.g, Jane Doe)" runat="server" style="width:250px;" class="form-control"></asp:TextBox><br />
                    <asp:CheckBox ID="grid1Details" ClientIDMode="Static" runat="server" Checked="false" AutoPostBack="true" OnCheckedChanged="Grid1CheckChanged" /><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="txtsourceaddress" CssClass="textClass" placeholder="Address..." runat="server" style="width:250px;" class="form-control"></asp:TextBox><br /><br />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Income">
            <ItemStyle HorizontalAlign="Left"></ItemStyle>
                <ItemTemplate>
                     <asp:TextBox ID="txtsourceincome" CssClass="textClass" placeholder="Income...(example: 1000)" runat="server" style="width:250px;" class="form-control txtsourceincome numeric"></asp:TextBox><br /><br />
                </ItemTemplate>
                       </asp:TemplateField>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                 <asp:Button ID="ButtonAdd" runat="server" Text="Add" 
                        onclick="ButtonAdd_Click" CssClass="grvAddButton" OnClientClick="return ValidateEmptyValue();return validate()" /><br /><br /><br>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                 <asp:Button ID="sourceDelete" runat="server" Text="Delete" CommandName="Delete"
                         CssClass="grvDelButton" OnClientClick="return confirm('are you sure?')"  /> <br /><br /><br />
                </ItemTemplate>
            </asp:TemplateField> 
            </Columns>
          </asp:gridview>
        </td>
    </tr>
</table>


Thanks in advance

modified 18-Dec-17 15:01pm.

QuestionAdvice on Partial View Pin
sunsher17-Dec-17 2:37
Membersunsher17-Dec-17 2:37 
Questionmaintain position DIV on Postback Pin
Member 1317428015-Dec-17 5:42
MemberMember 1317428015-Dec-17 5:42 
AnswerRe: maintain position DIV on Postback Pin
jkirkerx18-Dec-17 8:17
professionaljkirkerx18-Dec-17 8:17 
GeneralRe: maintain position DIV on Postback Pin
Member 1317428018-Dec-17 23:41
MemberMember 1317428018-Dec-17 23:41 
QuestionProblem consuming soap web service - content mismatch Pin
anto200515-Dec-17 5:42
Memberanto200515-Dec-17 5:42 
AnswerRe: Problem consuming soap web service - content mismatch Pin
Richard Deeming18-Dec-17 2:40
mveRichard Deeming18-Dec-17 2:40 
GeneralRe: Problem consuming soap web service - content mismatch Pin
anto200518-Dec-17 5:44
Memberanto200518-Dec-17 5:44 
GeneralRe: Problem consuming soap web service - content mismatch Pin
Richard Deeming18-Dec-17 6:34
mveRichard Deeming18-Dec-17 6:34 
QuestionHow to fix error "the type or namespace name 'CustomerBAL' could not be found (are you missing a using directive or an assembly reference) Pin
Member 1357490013-Dec-17 21:50
MemberMember 1357490013-Dec-17 21:50 
AnswerRe: How to fix error "the type or namespace name 'CustomerBAL' could not be found (are you missing a using directive or an assembly reference) Pin
pt140113-Dec-17 22:00
Memberpt140113-Dec-17 22:00 
GeneralRe: How to fix error "the type or namespace name 'CustomerBAL' could not be found (are you missing a using directive or an assembly reference) Pin
Member 1357490013-Dec-17 22:56
MemberMember 1357490013-Dec-17 22:56 
QuestionHow to incorporate pagination feature into my repository Pin
Mou_kol13-Dec-17 3:31
MemberMou_kol13-Dec-17 3:31 
AnswerRe: How to incorporate pagination feature into my repository Pin
Richard Deeming13-Dec-17 7:17
mveRichard Deeming13-Dec-17 7:17 
GeneralRe: How to incorporate pagination feature into my repository Pin
Mou_kol14-Dec-17 20:33
MemberMou_kol14-Dec-17 20:33 
GeneralRe: How to incorporate pagination feature into my repository Pin
F-ES Sitecore14-Dec-17 22:56
mveF-ES Sitecore14-Dec-17 22:56 
GeneralRe: How to incorporate pagination feature into my repository Pin
Richard Deeming18-Dec-17 1:47
mveRichard Deeming18-Dec-17 1:47 
GeneralRe: How to incorporate pagination feature into my repository Pin
Mou_kol18-Dec-17 20:49
MemberMou_kol18-Dec-17 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.