Pop-up Message Box

J

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
 
E

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
 
P

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?');");

}
 
J

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top