Solved

Show validation messages on formview pageindex changing event

Posted on 2010-11-10
5
382 Views
Last Modified: 2012-05-10
I am updating the current record on the pageindexchanging event on my formview if the page is valid.  If it is not valid I would like it to show the validation control messages where data is not valid; like how it works when you click the Update button.  I'm not sure what command I need to use to do this.  My current code is attached.
Protected Sub fvProjects2_PageIndexChanging(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles fvProjects2.PageIndexChanging

        Page.Validate()


        If Page.IsValid Then
            fvProjects2.UpdateItem(True)
        Else


        End If




    End Sub

Open in new window

0
Comment
Question by:imstac73
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34105940
       If Page.IsValid Then
            fvProjects2.UpdateItem(True)
        Else
           lblMessage.Visible = True
            lblMessage.Text = "data is not valid."
            lblMessage.ForeColor = System.Drawing.Color.Red
        End If

Then you create the label on the input form.

That's how I would do it but there are folks here who may have better ideas.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34106235
This would be the label on input

<FORM...

<asp:Label ID="lblMessage" runat="server" Text="Result:" Visible="false"></asp:Label>
</FORM>
Sorry I forgot it
0
 

Author Comment

by:imstac73
ID: 34106305
I already have multiple validation controls in my form.  How do I get it to only make visible  the validation controls where the control value that it validates is invalid?  Here is my edititemtemplate.

<EditItemTemplate>
        
            <table cellpadding="0" width="900" cellspacing="0" border="0">
            <tr valign="top">
                <td width="20%"></td>
                <td width="60%" align="center"><PagerSettings FirstPageText="First" LastPageText="Last" Mode="NextPreviousFirstLast"
            NextPageText="Next" PageButtonCount="100" PreviousPageText="Previous" /></td>
                 <td width="20%" align="right">  
                 <div style="width:115px;">
                <div class="linkbutton-l"><asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update"></asp:LinkButton></div>
                <div class="linkbutton-r"> 
                <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton></div>
                    <div class="clear"></div>
                    </div>
                
                </td>
            </tr>
            </table><br />
            
            <table class="projects" width="900" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="header" style="width: 250px">
                        Priority:</td>
                    <td class="details" style="width: 292px">
                        <asp:DropDownList ID="ddl_priority" runat="server" SelectedValue='<%# Bind("Priority") %>'>
                            <asp:ListItem>1</asp:ListItem>
                            <asp:ListItem>2</asp:ListItem>
                            <asp:ListItem>3</asp:ListItem>
                            <asp:ListItem>4</asp:ListItem>
                            <asp:ListItem>5</asp:ListItem>
                        </asp:DropDownList></td>
                    <td class="header" style="width:250px">
                        Win Probability:</td>
                    <td class="details">
                        <asp:DropDownList ID="ddl_winprob" runat="server" SelectedValue='<%# Bind("Win_Probability") %>'>
                            <asp:ListItem Value="20" Selected="True">20%</asp:ListItem>
                            <asp:ListItem Value="40">40%</asp:ListItem>
                            <asp:ListItem Value="60">60%</asp:ListItem>
                            <asp:ListItem Value="80">80%</asp:ListItem>
                        </asp:DropDownList>
                        <asp:Label ID="Label11" runat="server" CssClass="requiredfield" Text="*"></asp:Label></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px">
                        Project Name:</td>
                    <td class="details" style="width: 292px">
                        <asp:TextBox ID="ProjectNameTextBox" runat="server" Text='<%# Bind("ProjectName") %>'
                            Width="246px" Height="33px" TextMode="MultiLine"></asp:TextBox>
                        <asp:Label ID="Label19" runat="server" CssClass="requiredfield" Text="*"></asp:Label></td>
                    <td class="header" style="width: 147px">
                        Est. Value:</td>
                    <td class="details">
                        <asp:TextBox ID="Est_ValueTextBox" runat="server" Text='<%# Bind("Est_Value") %>'
                            Width="64px"></asp:TextBox>
                        <asp:Label ID="Label18" runat="server" CssClass="requiredfield" Text="*"></asp:Label>
                        <strong>Million<asp:CompareValidator
                            ID="cvEstValue" runat="server" ControlToValidate="Est_ValueTextBox" CssClass="errormessages"
                            Display="Dynamic" ErrorMessage="Estimated Value must be greater than 0. " Operator="GreaterThanEqual"
                            SetFocusOnError="True" Type="Double" ValidationGroup="Errors" ValueToCompare="0.0"
                            Width="100%"></asp:CompareValidator></strong></td>
                </tr>
                <tr>
                    <td class="header">
                        Project Description:</td>
                    <td class="details">
                        <asp:TextBox ID="ProjectDescriptionTextBox" runat="server" Height="60px" Text='<%# Bind("ProjectDescription") %>'
                            Width="300px" MaxLength="100" TextMode="MultiLine"></asp:TextBox><br />
                        <cc1:TextBoxCounter ID="tboxcounterdescription" runat="server" Font-Bold="True" ForeColor="#000000"
                            MaxCharacterLength="1000" TextBoxControlId="ProjectDescriptionTextBox" Width="300px" DataFormatString="Character Max. {5}; {3} remaining" />
                    </td>
                    <td class="header" style="width: 147px; height: 48px">
                        Owner:</td>
                    <td class="details" style="height: 48px">
                        <asp:DropDownList ID="ddl_owner" runat="server" DataSourceID="SqlDataOwners" DataTextField="Owner"
                            DataValueField="OwnerID" SelectedValue='<%# Bind("OwnerID") %>' Width="216px">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td class="header">
                        Comments/Next Steps:</td>
                    <td class="details" colspan="3">
                        <asp:TextBox ID="CommentsTextBox" runat="server" Height="60px" Text='<%# Bind("Comments") %>'
                            Width="720px" MaxLength="500" TextMode="MultiLine"></asp:TextBox><br />
                        <cc1:TextBoxCounter ID="tboxcountercomments" runat="server" Font-Bold="True" ForeColor="#000000"
                            MaxCharacterLength="500" TextBoxControlId="commentstextbox" Width="300px" DataFormatString="Character Max. {5}; {3} remaining" />
                    </td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Location:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <asp:TextBox ID="LocationTextBox" runat="server" Text='<%# Bind("Location") %>' Width="261px"></asp:TextBox></td>
                    <td class="header" style="width: 147px; height: 20px">
                        Market:</td>
                    <td class="details" style="height: 20px">
                        <asp:DropDownList ID="ddl_market" runat="server" DataSourceID="SqlDataMarkets" DataTextField="Market"
                            DataValueField="MarketID" SelectedValue='<%# Bind("MarketID") %>' Width="224px">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Bid Release Date:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <cc2:DatePicker ID="date_bidrelease" runat="server" CalendarPosition="DisplayRight"
                            DateValue='<%# Bind("Bid_ReleaseDate") %>' />
                        &nbsp;<asp:Label ID="Label20" runat="server" CssClass="requiredfield" Text="*"></asp:Label>                      
                        <br />
                        <asp:CompareValidator ID="cvbidrelease" runat="server" ControlToValidate="date_bidrelease"
                            CssClass="errormessages" Display="Dynamic" ErrorMessage="Bid Release Date must be a valid date (mm/dd/yyyy)"
                            Operator="DataTypeCheck" Type="Date" SetFocusOnError="True"></asp:CompareValidator>
                    </td>
                    <td class="header" style="width: 147px; height: 20px">
                        Est. Bid Date:</td>
                    <td class="details" style="height: 20px">
                        <cc2:DatePicker ID="dpbiddate" runat="server" CalendarPosition="DisplayRight" DateValue='<%# Bind("Est_BidDate") %>' />
                        <asp:Label ID="Label21" runat="server" CssClass="requiredfield" Text="*"></asp:Label>
                        <br />
                        <asp:CompareValidator ID="cvbiddate" runat="server" ControlToValidate="dpbiddate"
                            CssClass="errormessages" Display="Dynamic" ErrorMessage="Est. Bid Date must be a valid date format (mm/dd/yyyy)."
                            Operator="DataTypeCheck" Type="Date" SetFocusOnError="True"></asp:CompareValidator></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Est. Const. Start Date:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <cc2:DatePicker ID="date_startdate" runat="server" CalendarPosition="DisplayRight"
                            DateValue='<%# Bind("Est_StartDate") %>' />
                        <asp:Label ID="Label22" runat="server" CssClass="requiredfield" Text="*"></asp:Label><br />
                        <asp:CompareValidator ID="cvconstartdate" runat="server" ControlToValidate="date_startdate"
                            CssClass="errormessages" Display="Dynamic" ErrorMessage="Est. Bid Date must be a valid date format (mm/dd/yyyy)."
                            Operator="DataTypeCheck" Type="Date" SetFocusOnError="True"></asp:CompareValidator></td>
                    <td class="header" style="width: 147px; height: 20px">
                        Construction
                        <br />
                        Duration:</td>
                    <td class="details" style="height: 20px">
                        <asp:TextBox ID="tboxconduration" runat="server" Width="58px" Text='<%# Bind("Est_Duration", "{0:N1}") %>'></asp:TextBox>
                        <asp:Label ID="Label23" runat="server" CssClass="requiredfield" Text="*"></asp:Label>
                        <strong>Months<br />
                            <asp:RequiredFieldValidator ID="rvduration" runat="server" ControlToValidate="tboxconduration"
                                CssClass="errormessages" Display="Dynamic" ErrorMessage="Construction Duration is required." SetFocusOnError="True"></asp:RequiredFieldValidator>
                            <asp:CompareValidator ID="cvconduration" runat="server" ControlToValidate="tboxconduration"
                                CssClass="errormessages" Display="Dynamic" ErrorMessage="Construction Duration must be greater than 0."
                                Operator="GreaterThan" Type="Double" ValueToCompare="0.0" SetFocusOnError="True"></asp:CompareValidator></strong></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Branch Office:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <asp:DropDownList ID="ddl_branch" runat="server" DataSourceID="SqlDataOffice"
                            DataTextField="Branch_Office" DataValueField="Branch_OfficeID" SelectedValue='<%# Bind("BranchOfficeID") %>'
                            Width="224px">
                        </asp:DropDownList></td>
                    <td class="header" style="width: 147px; height: 20px">
                        Sponsor:</td>
                    <td class="details" style="height: 20px">
                        <asp:DropDownList ID="ddl_sponsor" runat="server" DataSourceID="SqlDataSponsors"
                            DataTextField="Sponsor" DataValueField="SponsorInitials" SelectedValue='<%# Bind("SponsorID") %>'
                            Width="229px">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        CM/GC:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <asp:TextBox ID="CM_GCTextBox" runat="server" Text='<%# Bind("CM_GC") %>' Width="286px"></asp:TextBox></td>
                    <td class="header" style="width: 147px; height: 20px">
                        Architect/<br />
                        Engineer:</td>
                    <td class="details" style="height: 20px">
                        <asp:TextBox ID="Architect_EngineerTextBox" runat="server" Text='<%# Bind("Architect_Engineer") %>'
                            Width="270px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Construction Type:</td>
                    <td class="details" style="width: 292px; height: 20px">
                        <asp:ListBox ID="lbox_ConstructionType" runat="server" Width="195px" DataSourceID="SqlDataConstructionTypes" DataTextField="Construction_Type" DataValueField="Construction_Type" Height="84px"></asp:ListBox><br />
                        <strong>Hold Ctrl or Shift button to select multiple values.</strong></td>
                    <td class="header" style="width: 147px; height: 20px">
                        Scope:</td>
                    <td class="details" style="height: 20px">
                        <asp:TextBox ID="ScopeTextBox" runat="server" Height="31px" Text='<%# Bind("Scope") %>'
                            Width="238px"></asp:TextBox>
                        <asp:TextBox ID="ModifiedDateTextBox"
                    runat="server" Text='<%# Bind("ModifiedDate") %>' Visible="False" Width="56px"></asp:TextBox><asp:TextBox
                        ID="ModifiedByTextBox" runat="server" ReadOnly="True" Text='<%# Bind("ModifiedBy") %>'
                        Visible="False"></asp:TextBox></td>
                </tr>
                <tr>
                    <td class="header" style="width: 168px; height: 20px">
                        Status:</td>
                    <td class="details" colspan="3" style="height: 20px">
                        <asp:DropDownList ID="ddl_status" runat="server" DataSourceID="SqlDataStatuses"
                            DataTextField="Status" DataValueField="ProjectStatusID" SelectedValue='<%# Bind("StatusID") %>'
                            Width="230px">
                        </asp:DropDownList></td>
                </tr>
            </table>
            <div style="width:115px; float:right;">
                <div class="linkbutton-l"><asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update"></asp:LinkButton></div>
                <div class="linkbutton-r"> 
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton></div>
                    <div class="clear"></div>
                    </div>        
           
            
        </EditItemTemplate>

Open in new window

0
 

Accepted Solution

by:
imstac73 earned 0 total points
ID: 34159715
To fix this I added custom navigation buttons to my pagertemplate and set causes validation to true.
0
 

Author Closing Comment

by:imstac73
ID: 34186457
Prior comments did not resolve the issue I was having.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert an ASPX page into PDF 7 32
Import a txt file into a DataGridView and TextBox 20 38
VB.Net - MemoryMappedFiles - Confirm receipt 2 19
Expression Evaluater 3 27
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question