Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2005, 05:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, there is a way to add the client side JavaScript.

I answered your question here: http://p2p.wrox.com/topic.asp?TOPIC_ID=28612

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Strugglin' by Tricky (Track 11 from the album: Maxinquaye) What's This?
 
Old March 30th, 2005, 06:04 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Imar solved it.

Take the onclick="ConfirmDelete();" out of the control definition.

Add a line to your page load, like:
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmdDelete.Attributes.Add("onclick", "ConfirmDelete();")
    End Sub
    (Of course, whatever other contents you have in your page load event should be left there as well.) The result is the following in the browser:
Code:
    <input type="submit" name="cmdDelete" value="Delete" id="cmdDelete" onclick="ConfirmDelete();" style="width:120px;" />
With that, you should be able to get this proposition to run.
 
Old March 31st, 2005, 11:26 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian, I tried doing what you told me to do. But, I'm getting errors when I try to run it. It says 'Object expected.' It comes up where I declare my variable 'dlt'. I think I'm doing something wrong in the coding. Here is what I have:

in the aspx.vb file:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  cmdDelete.Attributes.Add("onclick", "ConfirmDelete();")
End Sub

aspx file:
<script>
function ConfirmDelete()
{
if (confirm("...") == false)
{
document.all["results"].value = "False";
}
else
{
document.all["results"].value = "True";
var dlt;
dlt = return confirm("Are you sure you want to delete? To delete, click \"OK.\"\n"
+ "Otherwise, click \"Cancel.\"");
}
}
function SubmitRoutine()
{
if (document.all["results"].value == "False")
{
return false;
}
else
{
return true;
}
}
        </script>
    </HEAD>

<form id="Form1" onsubmit="return SubmitRoutine();" method="post" runat="server">
            &nbsp;&nbsp;&nbsp; <INPUT type="hidden" name="results" value="dlt">

**At the very bottom of my form near the end of the body:

<TR>
                                    <TD><asp:button id="cmdDelete" runat="server" Width="120px" Text="Delete"></asp:button></TD>
                                </TR>

Can you please tell me what's wrong w/this? Thanks so much for what you've done.

 
Old March 31st, 2005, 12:13 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I've gotten rid of the variable 'dlt' which has gotten rid of the error. However, regardless of whether they click on 'cancel' or 'ok', it still executes 'delete'. All the other buttons are fine. I think I'm not passing in the values correctly and that is why it's executing regardless. This is the modified version of my code:

function ConfirmDelete()
{
// var dlt;
// dlt =
return confirm("Are you sure you want to delete? To delete, click \"OK.\"\n"
+ "Otherwise, click \"Cancel.\"");
if (confirm("...") == false)
{
document.all["results"].value = "False";
}
else
{
document.all["results"].value = "True";

}
}
function SubmitRoutine()
{
if (document.all["results"].value == "False")
{
return false;
}
else
{
return true;
}
}
        </script>
    </HEAD>

<form id="Form1" onsubmit="return SubmitRoutine();" method="post" runat="server">
            &nbsp;&nbsp;&nbsp; <INPUT type="hidden" name="results" value="results">

<TR>
                                    <TD><asp:button id="cmdDelete" runat="server" Width="120px" Text="Delete"></asp:button></TD>
                                </TR>

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      cmdDelete.Attributes.Add("onclick", "ConfirmDelete();")
 End Sub

Can someone please tell me what is wrong here? Thanks.

 
Old March 31st, 2005, 12:48 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When you use return in a JScript function, you leave the function. Therefore all of the JScript after
Code:
      return confirm("Are you sure you want to delete?  To delete, click \"OK.\"\n"
                   + "Otherwise, click \"Cancel.\"");
                   in function ConfirmDelete will never be run. Try changing to
Code:
    function ConfirmDelete()
Code:
      {
         if (confirm("Are you sure you want to delete?  To delete, click \"OK.\"\n"
                   + "Otherwise, click \"Cancel.\"") == false)
         {
            document.all["results"].value = "False";  
         }
         else
         {
            document.all["results"].value = "True";

         }
      }

    function SubmitRoutine()
      {
         if (document.all["results"].value == "False")
         {
            return false;
         }
         else
         {
            return true;
         } 
      }
      Also, I think I would omit the value="results" from the results hidden control. The only thing you are looking for is whether that control == "False". Since "" != "False", you are OK to have that value in the control. (Why send more characters to the browser than needed, right?)
Also, hidden controls don't show (they [u]are</u> hidden, after all), so formatting them with &nbsp;s is fruitless. (Why send more characters to the browser than needed, right?)

Anyway, since the hidden control never gets set, the onsubmit of the form never finds a false value to interfere with the submittal.
 
Old March 31st, 2005, 01:08 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, everything is working fine. But, now there is another problem. When I load the page and click on all of the other buttons, they do as they're supposed to. But if I click 'delete' and choose 'cancel' and then try to click the other buttons, they don't execute. I know the reason is because SubmitRoutine is set to 'false'. Is there any way for me to set it to true so that it won't affect the other buttons? Thanks.

 
Old March 31st, 2005, 01:28 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What is happening is that the hidden control gets set to "False", and stays that way.

Modify the SubmitRoutine as follows:
Code:
    function SubmitRoutine()
      {
         if (document.all["results"].value == "False")
         {
            document.all["results"].value = "True";  // The value having already been read, it can be 'reset'.
            return false;
         }
         else
         {
            return true;
         } 
      }
 
Old March 31st, 2005, 01:41 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, everything is fine now. I thank Brian and everyone else for all of their help! :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
MessageBox help Barkils C# 1 July 16th, 2007 09:30 PM
MessageBox Lalit Pradhan ASP.NET 2.0 Professional 1 July 5th, 2006 12:03 PM
MessageBox Ric_H General .NET 2 April 19th, 2006 01:45 PM
How to use MessageBox johnsonlim026 ASP.NET 1.0 and 1.1 Basics 7 June 17th, 2005 10:21 AM
MessageBox asbayani ASP.NET 1.0 and 1.1 Basics 3 July 29th, 2003 03:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.