Need help on popping up a java script popup box when clicked on a LinkButton.

L

Learner

Hello,
I have two buttons on one of my VehicleDetails.aspx page. Obiviously
these two buttons takes the user to two different pages. Now my client
is interested in having a linkbutton instead of the two buttons. Once
the user clicks on the linkbutton a javascript dialog box popsup that
says "Is the Lessee buying this vehicle?" and with two buttons "Yes"
and "No". If user clicks "yes" it should go to DealerQuestions.aspx"
and if "No" it goes "lesseePurchase.aspx" page.

As of now I have two buttons like I mentioned earlier where in under
the button click event I am doing a Response.Redirect() to the said
pages.


could some one help me how do I accomplish the linkbutton and adding a
javascript functionality to it as I said on the top?

This is what I put to get the javascript popup box to popup when
clicked on the linkbutton

_lnkDLpurchase.Attributes.Add("onclick", "window.alert('Will Lessee buy
this vehicle?.');return true;")

But I don't know how to get two buttons and exectue two different codes
based on what was clicked on.


Please help,
Thanks in advance
-L
 
B

Bruno Alexandre

"alert" is to show a a message with no buttons...
"prompt" is to show a question and a textbox where the user input something
and it will be used as a javascript variable
"confirm" is what you want, it shows a question with 2 buttons...

so change this:
_lnkDLpurchase.Attributes.Add("onclick", "window.alert('Will Lessee buy
this vehicle?.');return true;")

into this:
_lnkDLpurchase.Attributes.Add("onclick", "if( confirm('Will Lessee buy
this vehicle?') ) return true; else return false;")
 
L

Learner

Hello Bruno,
Good explanation. Now I understand the differences on how to get a
pop window based on our need. I test it and I get two buttons on the
popup box.

Now one more help. If uses clicks on "Yes" it should execute the code

Response.Redirect("LesseePurchase.aspx?DealerShipID=" &
_lblDealerShipIDValue.Text)

when "No" this should go to another page

Response.Redirect("DealerQuestions.aspx?DealerShipID=" &
_lblDealerShipIDValue.Text)

Could you also help me wih this one too?

Thanks
-L
 
G

Gary

L,
From your last post, I don't think you want to mess with Javascript.
You can't easily convert that Javascript response into a
Response.Redirect, since JS runs on the client, and the
response.redirect is on the server.

What I do in lieu of JS confirmations is create a separate aspx page
for the confirmation. The link button links to this page, and then you
bind the yes/no buttons to the Response.Redirects to the appropriate
pages from there.

So the two logic branches would be:

vehicle details page --> link button --> "Is the Lessee buying this
vehicle?" page --> yes button --> DealerQuestions page

-OR-

vehicle details page --> link button --> "Is the Lessee buying this
vehicle?" page --> no button --> LesseePurchase page

I hope this helps. I use this for Delete confirmations as well.

Thanks,
Gary
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top