locked
Comparisons across multiple tables RRS feed

  • Question

  • User981378579 posted

    Hi All,

    I would like to set up a series of validations across several tables that aren't necessarily displayed on the page.  For instance, if the price on a work order does not match the price on my PO, I would like a line of text across the top of the work order page which says "The work order price does not match the purchase order price of $100.00.".  I know how to query the database to get this data and make the comparison, but what is the best route for displaying these messages if there could be 5 messages or more displayed at once?  Is there a way to write these statements to be displayed on a ValidationSummary perhaps?  If so, could you provide a simple example to show this being done using VB?

    Thanks in advance.

    Wednesday, March 26, 2008 6:45 PM

Answers

  • User62194485 posted

    This is something I've done.. not sure if it's the best route, but I right now it seems pretty good to me.
    Make sure to have a ValidationSummary control on the page, and use this code.  It should plop a new msg into your ValidationSummary. :)

    Public Shared Function GetCustomValidator(string ErrorMessage) As CustomValidator

     Dim cv As New CustomValidator()

     cv.IsValid = false
     cv.ErrorMessage = ErrorMessage

     Return cv 

    End Function
     

    Then do:

    Page.Controls.Add(GetCustomValidator("Price doesn't match"))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 27, 2008 10:57 PM

All replies

  • User62194485 posted

    This is something I've done.. not sure if it's the best route, but I right now it seems pretty good to me.
    Make sure to have a ValidationSummary control on the page, and use this code.  It should plop a new msg into your ValidationSummary. :)

    Public Shared Function GetCustomValidator(string ErrorMessage) As CustomValidator

     Dim cv As New CustomValidator()

     cv.IsValid = false
     cv.ErrorMessage = ErrorMessage

     Return cv 

    End Function
     

    Then do:

    Page.Controls.Add(GetCustomValidator("Price doesn't match"))

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 27, 2008 10:57 PM
  • User981378579 posted

    Thank you for your reply!  This sounds like exactly what I'm looking for.

    I've created a test page to try your suggestion, but receive an error that says "System.Web.HttpException: Control 'ctl01' of type 'CustomValidator' must be placed inside a form tag with runat=server".  Would you please point out what I'm doing wrong?  Thanks again.

     Page code:

     <%@ Page Language="VB" MasterPageFile="~/SageWeb.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="SageWork_test" title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">

    <asp:ValidationSummary ID="ValidationSummary" runat="server" />

    </asp:Content>

    Code Behind:

    Partial Class SageWork_test

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Page.Controls.Add(GetCustomValidator("Test error message."))

    End Sub

    Public Shared Function GetCustomValidator(ByVal ErrorMessage As String) As CustomValidator

    Dim cv As New CustomValidator()

    cv.IsValid = False

    cv.ErrorMessage = ErrorMessage

    Return cv

    End Function

    End Class

    Friday, March 28, 2008 12:32 PM
  • User62194485 posted

     Sorry - should have mentioned it must go within a form.

    So add a form. formID.Controls.Add()

    Friday, March 28, 2008 8:12 PM
  • User981378579 posted

    Hi Wordracr,

    Thanks for your patience.  Now I receive an error stating that my page can have only one form.  It references the form on my .master page.  When I try to reference that form, I receive errors that I can't change a form that contains server tags <% %>.  Thanks again.

    Here is what I have now.

    CODE BEHIND:

    Partial
    Class SageWork_test

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    formID.Controls.Add(GetCustomValidator("Test error message."))

    End Sub

    Public Shared Function GetCustomValidator(ByVal ErrorMessage As String) As CustomValidator

    Dim cv As New CustomValidator()

    cv.IsValid = False

    cv.ErrorMessage = ErrorMessage

    Return cv

    End Function

    End Class

     PAGE:

    <%@ Page Language="VB" MasterPageFile="~/SageWeb.master" AutoEventWireup="false" CodeFile="Alerts.aspx.vb" Inherits="SageWork_test" title="Untitled Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">

    <form id="formID" runat="server">

    <asp:ValidationSummary ID="ValidationSummary" runat="server" />

    </form>

    </asp:Content>

    Monday, March 31, 2008 6:54 PM