Home All Groups Group Topic Archive Search About
Author
3 May 2005 4:00 AM
JP
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

Author
3 May 2005 9:24 AM
Eliyahu Goldin
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

Show quoteHide quote
"JP" <J*@discussions.microsoft.com> wrote in message
news:B7540788-69DE-40A0-9CA4-99FB993AFBDD@microsoft.com...
> 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
Author
4 May 2005 1:45 PM
Prodip Saha
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?');");

}


Show quoteHide quote
"JP" <J*@discussions.microsoft.com> wrote in message
news:B7540788-69DE-40A0-9CA4-99FB993AFBDD@microsoft.com...
> 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
Author
4 May 2005 5:26 PM
JP
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

Show quoteHide quote
"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" <J*@discussions.microsoft.com> wrote in message
> news:B7540788-69DE-40A0-9CA4-99FB993AFBDD@microsoft.com...
> > 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
>
>
>