tags:

views:

2102

answers:

3

I am checking emailId exists in DB, If Exists I am looking to create a Ok/Cancel confirmation dialog. if user say "Ok" I am redirecting to some other form.

My code is :

If emailId = True Then
    If MsgBox("Your email address exists in our database. Click OK to update your   Details.", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, Title:="NJ Golf Resort") = MsgBoxResult.Ok Then
        Response.Redirect("~/articles.asp?a=" & a & "&b=" & b )
    End If
End If

for above code i m getting error :

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application

+5  A: 

I think this is a website code in ASP.Net, and what you are trying to do is display msgbox on server, this can not be done as the user is interacting with the web browser on client side, you may better use javascript to dispaly msgbox

Cheers.

Ratnesh Maurya
i know writing javascript for validations like required fields.in this case i have to do coding in back end .step 1 : Check for EmailId existance in DB.If Existsstep 2 : Show a message to user saying "Your email address exists in our database. Click OK to update your Details" If user press OK then i have to redirect them to contact page.If u have any samples,let me know
jyoti
Refer the answer below
Kusek
You need to use AJAX, Answer by Kusek is good.
Ratnesh Maurya
I need to do this task using AJAX .I m not getting how to do this for following condition using AJAX.step 1 : Check for EmailId existance in DB.If Exists step 2 : Show a message to user saying "Your email address exists in our database. Click OK to update your Details" If user press OK then i have to redirect them to contact page.
jyoti
call a http post or webservice (which returns true if email id already exists) from javascript use XMLHttpRequest object. If true display msgbox. Refer to the answer by Kusek.http://www.w3schools.com/Ajax/ajax_intro.asplook at the example there, hope it helps :)
Ratnesh Maurya
I have Updated the Code for AJAX.
Kusek
using <ajaxToolkit:ConfirmButtonExtender> and <ajaxToolkit:ModalPopupExtender>.after verifying EmailId in DB with code behind if emailId exists in DB, then i should pop up ModalPopupExtender for confirmaion.
jyoti
+1  A: 

Simply put, you shouldn't be using System.Windows.Forms.Messagebox in an ASP.NET application, because message boxes will only work properly for Windows Forms applications.

Jon Limjap
A: 
function redirect(a,b){
      if(confirm('Your email id is in DB')){
          window.location.href='/articles.asp?a='+a+'&b='+b;
       }
}

In serverside call the above client side function as

If emailId = True Then
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "EmailID", String.Format("redirect({0},{1});", aValue, bValue), true);

    /*For Asp.net AJAX use the following code*/
    ScriptManager.RegisterStartupScript(this.GetType(), "EmailID", String.Format("redirect({0},{1});", aValue, bValue), true);

End If

Note:I have given the C# code.Translate to VB.

Kusek
Added /*For Asp.net AJAX use the following code*/ ScriptManager.RegisterStartupScript(this.GetType(), "EmailID", String.Format("redirect({0},{1});", aValue, bValue), true);------------- i m getting following error ----> wucEmailSignUp.ascx.vb(40): error BC30456: 'ClientScript' is not a member of 'System.Web.UI.ScriptManager'.
jyoti
ScriptManager.RegisterStartupScript(this, this.GetType(), "as", "script", true); this Should work Remove the line this.Page.ClientScript.RegisterStartupScript(....... For AJAX only the above line is enough
Kusek