How to prevent a page postback according to user choice

J

Joe Abou Jaoude

hi,

i have a linkbutton that deletes records from the database. I want to be
sure that the user didn't press it unintentionally , so on the client
side I want to use an alert window to make the user confirm his request
before posting the page to the server.

my question is how can i postback the page if the user presses the yes
button in the alert window and ho can i prevent the postback when the
user presses No

thank you
 
A

anon

The way I have hacked this before is to use a custom validator that asks the
user if they wish to continue but only if a page variable was set (say
"linkclick"). Declare this variable within the page (javascript) and set it
as 0. Then in your code add the onClick attribute for your linkbutton to be
"linkclick=1;" - the ; is important as dotnet will append postback logic to
this.

e.g. linkClick.Attributes.Add("onClick", "linkclick=1;");

That way the the validator will ask the user and control whether it should
post back or not when ever the use clicks the link but not another button.
Remember to reset linkclick=0 when the user says responds no.

D
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top