troubleshooting Question

requiredfiledvalidator of one button affects a second button

Avatar of metropia
metropiaFlag for United States of America asked on
ASP.NETC#
6 Comments2 Solutions377 ViewsLast Modified:
I created a RequiredFieldValidator control, to ensure that a comment is enter before saving it.

the validator is control by a button named btnSaveLog

I created another button to redirect to another page, this button is independent from whether the suer has entered or not a comment on the textbox that has the validator assigned to.

For some reason, when I click the button to go to the other page, the error message of the validator for the text box gets triggered.

Can someone show me what am I doing wrong?

<tr>
            <td colspan="2" class="style6" valign="top">
                <asp:TextBox ID="txtComments" runat="server" Height="110px" TextMode="MultiLine" 
                    Width="410px" BorderColor="#CCCCFF" BorderStyle="Solid" BorderWidth="1px" 
                    Font-Names="Verdana" Font-Size="Small" CssClass="style5"></asp:TextBox><br />
                <asp:RequiredFieldValidator 
                    ID="reqComment" 
                    runat="server" 
                    ErrorMessage="YOU MUST ENTER A COMMENT BEFORE ADDING A NEW COMMENT." 
                    ControlToValidate="txtComments" 
                    InitialValue="" 
                    Font-Names="Verdana" 
                    Font-Size="X-Small" 
                    ForeColor="#FF0066" 
                    SetFocusOnError="False"
                    EnableClientScript="true">
                </asp:RequiredFieldValidator>
            </td>            
            <td colspan="4" class="style10" valign="top" align="right">
                <asp:TextBox ID="txtLastContactDateAndLog" runat="server" CssClass="style11" 
                    Height="107px" TextMode="MultiLine" Width="410px" BorderColor="#CCCCFF" 
                    BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="Small" 
                    ReadOnly="True"></asp:TextBox>
            </td>               
        </tr>        
        <tr>
            <td colspan="3">
                <asp:Button ID="btnSaveLog" runat="server" Text="Add New Comment" 
                    BorderStyle="Outset" Font-Names="Verdana" Font-Size="Small" 
                    onclick="btnSaveLog_Click" TabIndex="1"  Width="150" />
            </td>
            <td colspan="3" align="right">
                <asp:Button ID="btnViewHistory" runat="server" Text="View Log History" 
                    BorderStyle="Outset" Font-Names="Verdana" Font-Size="Small" TabIndex="2" 
                    CssClass="style22" Width="150" onclick="btnViewHistory_Click" />
            </td>
               
        </tr>
ASKER CERTIFIED SOLUTION
Bill Nolan
CTO Renegade Systems

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros