CustomValidator in UpdatePanel

Last post 12-10-2006 9:46 PM by Dev4. 1 replies.

Sort Posts:

  • CustomValidator in UpdatePanel

    08-23-2006, 7:08 AM
    • Loading...
    • memento
    • Joined on 06-01-2006, 9:43 AM
    • Posts 61

    I have a BulkEditGridView inside an Update panel and have the following issue:

    I have a texbox linked to a int column in the database. I use a CustomValidator to check if the inserted value is, in fact, an int. In adition, users should be able to introduce "NR" if they can't respond. It is the CustomValidator's job to see if the text is an int or NR. In the later case, it should change the textbox value from NR to "-1000", a code that represents NR in the database.

    It works fine without the UpdatePanel, but once I use this panel it stops working, because apparently it can't seem to change the Textbox's value to -1000. The code that makes the switch is:

     

    public void testNANRNumberFormatBGV(Page page, string textBoxControlName, GridView gv, ServerValidateEventArgs args)
        {
            if (args.Value == "NR")
            {
                TextBox tb = (TextBox)gv.FindControl(textBoxControlName);
                tb.Text = "-1000";
                args.IsValid = true;
            }
        }
     Does anyone have any ideas on why this happens?
  • Re: CustomValidator in UpdatePanel

    12-10-2006, 9:46 PM
    • Loading...
    • Dev4
    • Joined on 12-10-2006, 9:29 PM
    • Posts 1

    Hi!

    You have to know which TextBox tb that you should set the value to.

    The simplest way to achieve this is

    <code> 

    int i = gv.RowIndex;

    TextBox tb = (TextBox)gv.Rows[i].FindControl(textBoxControlName);

    if(tb != null)

    {

         tb.Text = "-1000";

         args.IsValid = true;

    }

    </code>

     

    I hope that helps...

    Jasper aka Dev4

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter