DataList with CompareValidator?

Discussion in 'ASP .Net' started by Scott.Metzger, Oct 7, 2009.

  1. Hi,

    I have a DataList and on the EditTemplaate I have a CompareValidator

    I am using an Update_Command for the DataList.
    The CompareValidator works fine and displays, however, the Update Command
    still fires and attempts to execute the code in the procedure.

    How do I check to see if the CompareValidator is 'active' or how do I keep
    the Update Command from fireing?

    <asp:DataList ID="listVetMed" runat="server" DataKeyField="eor_supplies_id"
    DataSourceID="dsVetMed" BorderStyle="Solid"
    OnEditCommand="Edit_Command"
    OnCancelCommand="Cancel_Command"
    OnDeleteCommand="Delete_Command"
    OnUpdateCommand="Update_Command">
    ....

    protected void Update_Command(object sender, DataListCommandEventArgs e)
    {
    DropDownList ddAnimalList =
    (DropDownList)e.Item.FindControl("ddAnimalList");
    string eor_supplies_id =
    listVetMed.DataKeys[e.Item.ItemIndex].ToString();
    Label lblcare_ts_id = (Label)e.Item.FindControl("lblcare_ts_id");
    Label lblQuarantineTsId =
    (Label)e.Item.FindControl("lblQuarantineTsId");
    TextBox txtQty = (TextBox)e.Item.FindControl("txtQty");
    DropDownList ddBSLLevel =
    (DropDownList)e.Item.FindControl("ddBSLLevel");
    DropDownList ddDateNeeded =
    (DropDownList)e.Item.FindControl("ddDateNeeded");
    TextBox txtNumDays = (TextBox)e.Item.FindControl("txtNumDays");


    DBService.UpdateVetMedAnimalPurchase(lblFiscalYear.Text,
    eor_supplies_id, lblcare_ts_id.Text,
    lblQuarantineTsId.Text,
    ddAnimalList.SelectedValue,
    txtQty.Text,
    ddBSLLevel.SelectedValue, ddDateNeeded.SelectedValue,
    txtNumDays.Text);

    listVetMed.ShowHeader = true;
    listVetMed.EditItemIndex = -1;
    listVetMed.DataBind();

    }


    Thanks,
    Scott
    Scott.Metzger, Oct 7, 2009
    #1
    1. Advertising

  2. On Oct 7, 9:53 pm, Scott.Metzger
    <> wrote:
    > Hi,
    >
    > I have a DataList and on the EditTemplaate I have a CompareValidator
    >
    > I am using an Update_Command for the DataList.  
    > The CompareValidator works fine and displays, however, the Update Command
    > still fires and attempts to execute the code in the procedure.
    >
    > How do I check to see if the CompareValidator is 'active' or how do I keep
    > the Update Command from fireing?
    >
    > <asp:DataList ID="listVetMed" runat="server" DataKeyField="eor_supplies_id"
    > DataSourceID="dsVetMed" BorderStyle="Solid"
    >      OnEditCommand="Edit_Command"
    >      OnCancelCommand="Cancel_Command"
    >      OnDeleteCommand="Delete_Command"
    >      OnUpdateCommand="Update_Command">
    > ...
    >
    > protected void Update_Command(object sender, DataListCommandEventArgs e)
    >     {
    >         DropDownList ddAnimalList =
    > (DropDownList)e.Item.FindControl("ddAnimalList");
    >         string eor_supplies_id =
    > listVetMed.DataKeys[e.Item.ItemIndex].ToString();
    >         Label lblcare_ts_id = (Label)e.Item.FindControl("lblcare_ts_id");
    >         Label lblQuarantineTsId =
    > (Label)e.Item.FindControl("lblQuarantineTsId");
    >         TextBox txtQty = (TextBox)e.Item.FindControl("txtQty");
    >         DropDownList ddBSLLevel =
    > (DropDownList)e.Item.FindControl("ddBSLLevel");
    >         DropDownList ddDateNeeded =
    > (DropDownList)e.Item.FindControl("ddDateNeeded");
    >         TextBox txtNumDays = (TextBox)e.Item.FindControl("txtNumDays");
    >
    >         DBService.UpdateVetMedAnimalPurchase(lblFiscalYear.Text,
    > eor_supplies_id, lblcare_ts_id.Text,
    >                                             lblQuarantineTsId.Text,
    > ddAnimalList.SelectedValue,
    >                                             txtQty.Text,
    > ddBSLLevel.SelectedValue, ddDateNeeded.SelectedValue,
    >                                             txtNumDays.Text);
    >
    >         listVetMed.ShowHeader = true;
    >         listVetMed.EditItemIndex = -1;
    >         listVetMed.DataBind();
    >
    >     }
    >
    > Thanks,
    > Scott


    Add the following code to the start of the UpdateCommand event
    handler:

    if (!Page.IsValid)
    return;
    Alexey Smirnov, Oct 8, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sjaakie Helderhorst

    Ivoking comparevalidator

    Sjaakie Helderhorst, Feb 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    318
    Sjaakie Helderhorst
    Feb 25, 2004
  2. Henke
    Replies:
    0
    Views:
    1,505
    Henke
    Feb 26, 2004
  3. =?Utf-8?B?ZG90bmV0IGJlZ2lubmVy?=

    CompareValidator and Autopostback

    =?Utf-8?B?ZG90bmV0IGJlZ2lubmVy?=, Apr 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    532
    =?Utf-8?B?ZG90bmV0IGJlZ2lubmVy?=
    Apr 13, 2004
  4. Axel Dahmen

    CompareValidator problem

    Axel Dahmen, Apr 17, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,550
    Axel Dahmen
    Apr 20, 2004
  5. Nevyn Twyll
    Replies:
    8
    Views:
    1,849
Loading...

Share This Page