PC Review


Reply
Thread Tools Rate Thread

call javascript from code behind

 
 
Mike
Guest
Posts: n/a
 
      4th Oct 2007
Ok, here is my story. I took over a web site that is using the asp.net wizard. This wizard has buttons within it, now, on one of the steps in the wizard I have a drop down. Depending if 'Delete' is selected in the drop down, I need to show a message box to ask the user 'you sure you want to delete?" if they click 'OK' it deletes, if they click cancel it does nothing.

So within the button click event, how can I show an confirmation box only if 'Delete' is selected in the drop down?

so I need something like this

if (dd.selecteditem.text == "delete")
{
I need to show a confirmation box;
}

then call my delete method only if 'OK' is clicked in the confirmation box, if cancel then nothing happens.

any suggestions on how this can be done?




 
Reply With Quote
 
 
 
 
David R. Longnecker
Guest
Posts: n/a
 
      4th Oct 2007
You could do something like this:

if (dd.selecteditem.text == "delete")
{

ClientScript.RegisterClientScriptBlock(this.GetType(), "DeletePopup", "<script>
confirm('Are you sure you want to delete?') </script>");

}

That'll pop up a JavaScript box with OK and Cancel as options and the text
can be programatically changed to include row information, etc.

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

> Ok, here is my story. I took over a web site that is using the asp.net
> wizard. This wizard has buttons within it, now, on one of the steps in
> the wizard I have a drop down. Depending if 'Delete' is selected in
> the drop down, I need to show a message box to ask the user 'you sure
> you want to delete?" if they click 'OK' it deletes, if they click
> cancel it does nothing.
>
> So within the button click event, how can I show an confirmation box
> only if 'Delete' is selected in the drop down?
>
> so I need something like this
>
> if (dd.selecteditem.text == "delete")
> {
> I need to show a confirmation box;
> }
> then call my delete method only if 'OK' is clicked in the confirmation
> box, if cancel then nothing happens.
>
> any suggestions on how this can be done?
>



 
Reply With Quote
 
Collin Chung
Guest
Posts: n/a
 
      4th Oct 2007
On Oct 4, 10:27 pm, "Mike" <M...@community.nospam.com> wrote:
> Ok, here is my story. I took over a web site that is using the asp.net wizard. This wizard has buttons within it, now, on one of the steps in the wizard I have a drop down. Depending if 'Delete' is selected in the drop down, I need to show a message box to ask the user 'you sure you want to delete?" if they click 'OK' it deletes, if they click cancel it does nothing.
>
> So within the button click event, how can I show an confirmation box only if 'Delete' is selected in the drop down?
>
> so I need something like this
>
> if (dd.selecteditem.text == "delete")
> {
> I need to show a confirmation box;
>
> }
>
> then call my delete method only if 'OK' is clicked in the confirmation box, if cancel then nothing happens.
>
> any suggestions on how this can be done?




Hi Mike,

You'd want to use the OnClientClick property of the button, which
calls a javascript function..

<asp:Button ID="Button1" runat="server" OnClientClick="return
MyFunction()" Text="My Button" />

and in your javascript

function MyFunction() {
if (dd.selecteditem.text != "delete") return true;
return confirm("you sure you want to delete?");
}

Some docs with examples here:
http://msdn2.microsoft.com/en-us/lib...ientclick.aspx

--
Collin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Javascript confirm from code behind tshad Microsoft ASP .NET 2 5th May 2009 09:26 PM
Call Javascript confirm from code behind tshad Microsoft C# .NET 7 5th May 2009 09:06 PM
how do I call a code-behind procedure from javascript? Scott M. Microsoft ASP .NET 3 31st Mar 2008 12:08 AM
call a javascript function within code behind sajithkahawatta Microsoft C# .NET 4 20th Jun 2007 03:04 PM
Call VB Code Behind Function from JavaScript??? jason.gyetko@epower-inc.com Microsoft ASP .NET 5 30th Jun 2006 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:03 PM.