473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Handling Return Confirm()

Hi All,
I am tring to figure out how to handle input from the confirm dialog. I am using a gridview on which the user can check some checkboxes and then clicks <asp:button> to submit.
I check a condition in the csharp code and based on a condition , I need to display a confirm dialog to the user. So when I do the check on the condition (Server Side) I use RegisterStartupScript to generate the Client Side script for the confirm prompt.

Expand|Select|Wrap|Line Numbers
  1.             if (resultRow != null)
  2.             {
  3.                 if (!Page.IsClientScriptBlockRegistered("InfoMessage"))
  4.                 {
  5.                     string strNumScript = "<script> confirm('Item has already been assigned. Do you wish to continue? ');</script>";
  6.                     Page.ClientScript.RegisterStartupScript(GetType(), "InfoMessage", strNumScript);
  7.                 }
  8.             }
  9.  
I have seen lots of examples where the script is added as an attribute to a control. I am confused by these examples and most seem to be more straight forward examples than what I am trying to do.

Can I use the input from the confirm to control execution in the csharp code. Am I on the wrong track here?

Regards
Oct 23 '07 #1
9 8106
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

So you want the return value (true or false) from the confirm to be passed or become available in your C# code?
Oct 23 '07 #2
Hello, thanks for your reply.
yes I wish to access the true / false value.

I am still trying to figure it out. I am trying to set a hidden field with the result. So far I've come up with ....

Expand|Select|Wrap|Line Numbers
  1. if (shippingRowExists == true)
  2.                         {
  3.                             if (!Page.IsClientScriptBlockRegistered("BoxNumberInfoMessage"))
  4.                             {
  5.                                 string strNumScript = @"<script language=""javascript"" type=""text/javascript"">document.aspnetform.hidUserConfirm.value = return confirm('Item has already been assigned. Do you wish to reassign? ');</script>";
  6.                                 Page.ClientScript.RegisterStartupScript(GetType(), "BoxNumberInfoMessage", strNumScript);
  7.                             }
  8.                         }
which renders as

[HTML]<script language="javascript" type="text/javascript">document.aspnetform.hidUserConfirm.val ue = return confirm('Item has already been assigned. Do you wish to reassign? ');</script>
<script type="text/javascript">[/HTML]

Its still not working quite right. The confirm is not opening.
Oct 23 '07 #3
acoder
16,027 Expert Mod 8TB
Remove "return" from your code. Also make sure that the code runs after the page has loaded.
Oct 23 '07 #4
Hello again, you are right about dropping the return. The confirm is now appearing. So thanks for that.

So I am setting the client side hidden field with the outcome from the confirm. The 'RegisterStartupScript' renders the javascript at the bottom of the page. My difficulty is where to catch the user input. I am not sure where in the C sharp the code is when waiting for the user input

I am beginning to think I am not going to be able to achieve what I set out to do using this method. Interestingly (and probably no surprise to most people) the javascript cannot set a server side hidden field - and the server side canot see the ordinary html hidden field. I am still curious if it is possible to capture the user response?

As Homer would put it ..... doh!
Oct 24 '07 #5
acoder
16,027 Expert Mod 8TB
So I am setting the client side hidden field with the outcome from the confirm. The 'RegisterStartupScript' renders the javascript at the bottom of the page. My difficulty is where to catch the user input. I am not sure where in the C sharp the code is when waiting for the user input
The code will set the value of the hidden field. What do you mean "where to catch the user input"? When you submit the form, the hidden form value will be available to your server-side code.
Oct 24 '07 #6
I click the assignment button - the page is posted back.
The row items in the gridview are checked for previous assignment. If already assigned, the confirm prompt code is executed - then the confirm is rendered. User clicks and the page finishes loading. It is all part of the same postback. Is this a crazy plan.

I did investigate if there is an event that gets raised when the page completes loading - I was hoping to do the check on the hidden field here but this didn't come good either.
Oct 24 '07 #7
acoder
16,027 Expert Mod 8TB
I click the assignment button - the page is posted back.
The row items in the gridview are checked for previous assignment. If already assigned, the confirm prompt code is executed - then the confirm is rendered. User clicks and the page finishes loading. It is all part of the same postback. Is this a crazy plan.
No, it's not a crazy plan.

You probably want to avoid repeated postbacks. For this, you can use Ajax.

You have two choices: either check the assignment on the first page (before the assignment button is clicked) and show up a confirm there if there has been a previous assignment.

The second choice is to show the confirm as you are doing and then use Ajax to run the server-code.

I think the first option makes more sense.
Oct 24 '07 #8
I went with option 1. I amended the prompt to the user to also confirm assignment and swapped the Assignment button with a Confirm Assignment, Cancel button. Not the most elegant soln perhaps but it does whats needed.

Thanks for all your very good feedback.
Oct 25 '07 #9
acoder
16,027 Expert Mod 8TB
You're welcome. Glad to see that you got it working. Post again if you have any more questions.
Oct 25 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
7
by: sindre | last post by:
Hi, Some place I use links to submit forms instead of a submit button. The way I have done this is: <a href="javascript:document.getElementById('<?php print "delete$i"...
1
by: Tchernov \(BioStar\) | last post by:
I write the web-page with the DataGrid-control, that has the Button-column with the delete-command. I want to capture the bubbled event from these buttons on the client side before this event...
5
by: Thrud | last post by:
I have a button (runat=server) with some VB code attached to its on click event which does data updates. I now want to add a warning to the user prompting them whether they really want to...
1
by: MDBloemker | last post by:
can anyone help me fathom out how to use this bit of code: Public Class Utilities Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox, _ ByVal strMessage As String)...
3
by: Craig G | last post by:
hi, im only learning javascript, i have this little code snippet that i wish to use. basically the code-behind page will display a little jscript confirm message box Public Sub...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
8
by: Peter Afonin | last post by:
Hello, I'm using Javascript in ASP.NET application to check whether at least one checkbox in datagrid has been checked. If validation fails, the user gets a warning. If he clicks OK, the form is...
5
by: GiJeet | last post by:
Hello, I'm trying to figure this code out. <input type="submit" onclick="if(!confirm('Are you sure?') return false; "... /> I know that if you return false in an event like this onclick it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.