 |
| 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
|
|
|
|

March 29th, 2005, 06:13 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, I finally got it to work w/the following code:
Dim scriptString As String
scriptString = "<script language=JavaScript>confirm('File Uploaded ')"
scriptString += "</"
scriptString += "script>"
RegisterClientScriptBlock("clientScript", scriptString)
I put this in my delete button sub. I was wondering if it was possible to change the 'ok' and 'cancel' buttons to 'yes' and 'no' buttons and in turn find out which was clicked. I wanted to execute deletion if 'yes'. Is there a way to do this? My execution to delete is in vb. How would I use the values from javascript w/ vb?
Also, is there a way to change the title in the message instead of saying "Microsoft Internet Explorer"? One additional question is if there is a way to not have the page clear out when the message appears. Can the message appear on the original page instead of having it blank out and then return to the page after the user has clicked on a button? Thanks again.
|
|

March 29th, 2005, 07:24 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Iâm afraid you cannot change the title or the button faces. (The browser controls this behavior.)
What you have here is sort of what you want to do, but not quite. confirm() returns a true or a false. ('confirm,' 'true' and 'false' are the case I have used here, and to javascript, it [u]matters</u>.)
But you are not doing anything with the value.
First of all, I would put this <script> </script> block in your .aspx fileâs <head> section.
Second, put the confirm into a function
Code:
function SubmitRoutine()
{
return confirm("File Uploaded");
}
Third, add to your <form> tag onSubmit="return SubmitRoutine();"
Having done that, when you click the delete button, the form submittal will not take place until the function has run. The function will return a true or false, depending on how the user interacts with the confirm(). If a false is returned, the submit will be terminated. If a true is returned, the form will be submitted.
Do not put any code in .NET for the delete button. All of this querying of the user will take place at the browser, with no round trips to the server. The server will not be involved unless they click the OK on the confirm(). (btw: you should ask the user a question in the confirm(); how can there be an OK or Cancel response to the statement "File Uploaded"? If the file has not yet been up loaded, I would put the prompt
Code:
return confirm("To upload the file, click \"OK.\"\n"
+ "Otherwise, click \"Cancel.\"");
This would prompt:
Code:
To upload the file, click "OK."
Code:
Otherwise, click "Cancel."
So, the whole thing, put together is
Code:
<html>
<head>
<script>
function SubmitRoutine()
{
return confirm("File Uploaded"); // Or whatever prompt you choose.
}
</script>
</head>
<body>
<form ... action=, id=, whatever ... onSubmit="return SubmitRoutine();">
<input type="submit" value="Delete">
. . .
</form>
</body>
</html>
|
|

March 29th, 2005, 07:56 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Quote:
quote:Originally posted by mh
[t]RegisterClientScriptBlock("clientScript", scriptString)
|
Sorry for the confusion, "RegisterClientScriptBlock" is what I meant.
Don't forget, if you want to change your submit button to an image you can replace it with an image and then in the click event call a function that submits the form. It takes a little more work, but once you have it worked out it can be reused.
J
|
|

March 30th, 2005, 11:24 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, it works the way I want it to now. But, there is one problem. The problem is that there are other buttons on this page in addition to the 'delete' button. Is there a way to only call this function for the 'delete' button than for all of them? Because right now, it is being called for all of my buttons. And I have a total of 5 buttons including the delete button. Is there something I can do about this?
|
|

March 30th, 2005, 12:24 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Would you be willing to post here the salient portions of what you have so far?
Is there a reason that you are resisting adding client-side code to handle this for you? RegisterClientScriptBlock creates client-side code anyway, so why not just add it to the static html?
|
|

March 30th, 2005, 12:33 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What I have so far is what you gave me:
<script>
function SubmitRoutine()
{
return confirm("Are you sure you want to delete? To delete, click \"OK.\"\n"
+ "Otherwise, click \"Cancel.\"");
}
</script>
***this is in the <head> section.
Then at the bottom are my buttons:
<TR>
<TD style="HEIGHT: 25px"><asp:button id="cmdEdit" runat="server" Width="120px" Font-Size="10" Text="Edit"></asp:button></TD>
</TR>
<TR>
<TD><asp:button id="cmdAdd" runat="server" Width="120px" Font-Size="10" Text="Add"></asp:button></TD>
</TR>
<TR>
<TD><asp:button id="cmdDelete" runat="server" Width="120px" Text="Delete"></asp:button></TD>
</TR>
<TR>
<td><asp:button id="cmdVendorList" runat="server" Width="120px" Text="Vendor List"></asp:button></td>
</TR>
<TR>
<td><asp:button id="cmdTrans" runat="server" Width="120px" Text="Transmittal"></asp:button></td>
</TR>
***The cmddelete button is the one I want the function to be used for.
And I originally had this code in my aspx. vb file:
Dim scriptString As String
scriptString = "<script language=JavaScript>confirm('File Uploaded ')"
scriptString += "</"
scriptString += "script>"
RegisterClientScriptBlock("clientScript", scriptString)
Disregard the message text, it was only used for testing purposes. But then I took it out. Inside my delete button in the aspx. vb is a stored procedure which is called to delete records.
Is there something else I should be doing? Or can you give me some more examples of what I should be doing? Thanks.
|
|

March 30th, 2005, 12:36 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
And I forgot that I also had this added in there:
<form id="Form1" method="post" runat="server" onSubmit="return SubmitRoutine();">
I'm pretty much new to asp.net, so I'm sorry if I'm giving everyone a hard time w/this. Any help is greatly appreciated.
|
|

March 30th, 2005, 02:47 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I did some looking, and apparently RegisterClientScriptBlock() is a way to conditionally add script to a web page. If I am right about that, it is not really useful for this undertaking.
I think what is happening is this: Every runat="server" button causes the <form> to be submitted. Since the code I recommended is in the submittal machinery of the form, it gets run every time you click a button.
If that in turn is right, then taking out the runat="server" on all the buttons would fix the problem. If you do not need to do server-side processing of every button, you could remove that property, and let the normal form-submittal be the 'whole story' regarding how this web page interacts with the application at the server.
Of course, this really interferes with the event-driven look-and-feel that .NET affords.
If you do that, then the issue becomes, âHow do I figure out which button was clicked?â
I think that can be overcome, but perhaps this is the thing to do: For the Delete button, run the javascript that I recommended, that is, a JScript function that presents a confirm();, but store the results in a hidden control in the form. Maybe name that function DeleteConfirm. In the Delete button add onclick="DeleteConfirm();":
Code:
function DeleteConfirm()
{
if (confirm("...") == false)
{
document.all["HiddenControl"].value = "False"; // A string, not a Boolean.
}
else
{
document.all["HiddenControl"].value = "True";
}
}
Add a function to the JScript, something like:
Code:
function SubmitRoutine()
{
if (document.all["HiddenControl"].value == "False")
{
return false;
}
else
{
return true;
}
}
In the form add onsubmit="return SubmitRoutine();"
So what will happen is that every button but the Delete button will [u]not</u> change the hidden control, but will submit the form as a post back, so as to run the button's _click event and so on.
Each time the form is submitted, the hidden control will be checked, and if not equal to the string "False", the form will be submitted.
The Delete button will put up the confirm(), setting the value of the hidden control first, before performing the submittal for post back.
If the control gets set to "False" the form submittal will be interrupted, and the post back will not take place.
I think that will do what you need. Thoughts?
|
|

March 30th, 2005, 03:30 PM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, this is what I have so far according to what you told me to do:
<head>
<script>
function DeleteConfirm()
{
if (confirm("...") == false)
{
document.all["results"].value = "False";
}
else
{
document.all["results"].value = "True";
}
}
function SubmitRoutine()
{
delete varchar;
delete = return confirm("Are you sure you want to delete? To delete, click \"OK.\"\n"
+ "Otherwise, click \"Cancel.\"");
if (document.all["results"].value == "False")
{
return false;
}
else
{
return true;
}
}
</script>
</HEAD>
<form id=Form1 onsubmit="return SubmitRoutine();" method=post runat="server">
<INPUT type="hidden" name = results value = delete>
and at the very bottom of my form are my buttons:
<TD><asp:button id=cmdDelete runat="server" onclick="DeleteConfirm();" Width="120px" Text="Delete"></asp:button></TD></TR>
I think I'm doing something wrong because my onclick for the delete button is giving me an error:
'DeleteConfirm' is not a member of 'ASP.VendorView_aspx'.
Also, all of my buttons need to use the server side processing so, I need to keep them there. Will this code work w/all my other buttons as well? Am I doing anything wrong? Thanks for your guidance.
|
|

March 30th, 2005, 05:14 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
.NET takes the contents of the
<asp:button id=cmdDelete runat="server" onclick="DeleteConfirm();" Width="120px" Text="Delete"></asp:button>
and tries to convert it to
<input type="submit" name="cmdDelete" value="Delete" id="cmdDelete" style="width:120px;" />
(As you can see, very little of the actual string for the control from VB remains in the html control at the browser.)
In this process, it does not have instructions for how to handle the onclick="DeleteConfirm();"
There must be a way to add client-side script to a control, so I am going to post a question on that next, to overcome this problem here.
Just as the Text property is translated to the value property, there might be a property that can be converted to the onclick property.
|
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 |
|
 |