Pop-up Message Box

Discussion in 'ASP .Net Datagrid Control' started by JP, May 3, 2005.

  1. JP

    JP Guest

    Hi;
    I have a DataGrid called "dgEvents"; one of the columns in the DataGrid is
    a template column and it is a TextBox called "txtEndDate". So, on Page Load,
    this column has a textbox in every row of the datagrid and there is no data
    in the textbox. The number of rows in the datagrid changes according to the
    search criteria the user used.

    What I want to do is, if the user puts a value (Date) in the textbox in any
    of the rows and when they click the Update Button, I want a pop-up message
    asking the user "Are you sure you want to do this?". If they click "Yes", I
    want to continue with the update else, I want to cancel the update.

    Well the problem is, I am not any good in JavaScript and I really need some
    help to get a javascript that will check to see if there is a value in any of
    the textboxes on the Update Button click event and if there is a value then
    have a pop up message asking "Are you sure you want to do this?"

    Please help
    JP
     
    JP, May 3, 2005
    #1
    1. Advertising

  2. 1. Define a client-side variable:
    var changed=false;

    2. For the textbox setup a client-side onchange event. In the event handler
    set
    changed=true;

    3. For the update button setup client-side onclick event handler. In the
    event handler write:
    if (changed)
    return confirm("Are you sure you want to do this?");
    else
    return true;

    Eliyahu

    "JP" <> wrote in message
    news:...
    > Hi;
    > I have a DataGrid called "dgEvents"; one of the columns in the DataGrid

    is
    > a template column and it is a TextBox called "txtEndDate". So, on Page

    Load,
    > this column has a textbox in every row of the datagrid and there is no

    data
    > in the textbox. The number of rows in the datagrid changes according to

    the
    > search criteria the user used.
    >
    > What I want to do is, if the user puts a value (Date) in the textbox in

    any
    > of the rows and when they click the Update Button, I want a pop-up message
    > asking the user "Are you sure you want to do this?". If they click "Yes",

    I
    > want to continue with the update else, I want to cancel the update.
    >
    > Well the problem is, I am not any good in JavaScript and I really need

    some
    > help to get a javascript that will check to see if there is a value in any

    of
    > the textboxes on the Update Button click event and if there is a value

    then
    > have a pop up message asking "Are you sure you want to do this?"
    >
    > Please help
    > JP
     
    Eliyahu Goldin, May 3, 2005
    #2
    1. Advertising

  3. JP

    Prodip Saha Guest

    You can wire the java script from your code in the ItemDataBound event of
    the datagrid control.

    Sample code:
    TextBox tb=(TextBox)e.Item.FindControl("txtEndDate");

    if(tb!=null)

    {

    tb.Attributes.Add("onclick","return confirm('Are you sure you want to do
    this?');");

    }


    "JP" <> wrote in message
    news:...
    > Hi;
    > I have a DataGrid called "dgEvents"; one of the columns in the DataGrid

    is
    > a template column and it is a TextBox called "txtEndDate". So, on Page

    Load,
    > this column has a textbox in every row of the datagrid and there is no

    data
    > in the textbox. The number of rows in the datagrid changes according to

    the
    > search criteria the user used.
    >
    > What I want to do is, if the user puts a value (Date) in the textbox in

    any
    > of the rows and when they click the Update Button, I want a pop-up message
    > asking the user "Are you sure you want to do this?". If they click "Yes",

    I
    > want to continue with the update else, I want to cancel the update.
    >
    > Well the problem is, I am not any good in JavaScript and I really need

    some
    > help to get a javascript that will check to see if there is a value in any

    of
    > the textboxes on the Update Button click event and if there is a value

    then
    > have a pop up message asking "Are you sure you want to do this?"
    >
    > Please help
    > JP
     
    Prodip Saha, May 4, 2005
    #3
  4. JP

    JP Guest

    Well; the problem is that in design view, the name of the (edit templatge
    item) textbox is "txtEndDate" but when you view the html source code in
    runtime the id of the textbox shows as "dgEvents__ctl1_txtEndDate" as the
    first control in the datagrid and the second row show as
    "dgWorkerSupervisor__ctl2_txtRoleEndDate" and so on. So the "ctl#" changes
    depends on how many rows you have in the datagrid.

    So, I am thinking I might have to have some kind of loop that will look for
    each textbox in the datagrid. But, I have no idea how to accomplish this
    though.

    JP

    "Prodip Saha" wrote:

    > You can wire the java script from your code in the ItemDataBound event of
    > the datagrid control.
    >
    > Sample code:
    > TextBox tb=(TextBox)e.Item.FindControl("txtEndDate");
    >
    > if(tb!=null)
    >
    > {
    >
    > tb.Attributes.Add("onclick","return confirm('Are you sure you want to do
    > this?');");
    >
    > }
    >
    >
    > "JP" <> wrote in message
    > news:...
    > > Hi;
    > > I have a DataGrid called "dgEvents"; one of the columns in the DataGrid

    > is
    > > a template column and it is a TextBox called "txtEndDate". So, on Page

    > Load,
    > > this column has a textbox in every row of the datagrid and there is no

    > data
    > > in the textbox. The number of rows in the datagrid changes according to

    > the
    > > search criteria the user used.
    > >
    > > What I want to do is, if the user puts a value (Date) in the textbox in

    > any
    > > of the rows and when they click the Update Button, I want a pop-up message
    > > asking the user "Are you sure you want to do this?". If they click "Yes",

    > I
    > > want to continue with the update else, I want to cancel the update.
    > >
    > > Well the problem is, I am not any good in JavaScript and I really need

    > some
    > > help to get a javascript that will check to see if there is a value in any

    > of
    > > the textboxes on the Update Button click event and if there is a value

    > then
    > > have a pop up message asking "Are you sure you want to do this?"
    > >
    > > Please help
    > > JP

    >
    >
    >
     
    JP, May 4, 2005
    #4
    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. kai
    Replies:
    7
    Views:
    4,949
  2. Microsoft News
    Replies:
    2
    Views:
    1,105
    Microsoft News
    Jan 27, 2005
  3. Alan Silver
    Replies:
    2
    Views:
    533
    Alan Silver
    Jul 12, 2005
  4. Meir
    Replies:
    1
    Views:
    3,329
    David Potts
    Jun 29, 2003
  5. Chris

    Pop-up?message box?

    Chris, Jun 16, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    139
    Chris
    Jun 17, 2004
Loading...

Share This Page