Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 23rd, 2006, 07:46 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default error when displaying messagebox on client browser

HI,

         I receive an error when the code executes on client browser. When i run the code from the local client PC, the error message box displays correctly. I read posts that say that i need to use JAVASCRIPTING. Could u guide me thru some scripts which can serve my purpose ??

ERROR in browser IS:

It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application

Try


If FileUpload1.HasFile Then
cnnNwind.Open()


'Define and execute the INSERT SqlCommand

' MsgBox(FormView1.DataKey.Value)

Dim strSQL As String = "UPDATE StudentRegistration SET Photo = '" & TextBox1.Text & "' " + _

"WHERE StudID = '" & FormView1.DataKey.Value & "' "

Dim cmdUpdates As SqlCommand = New SqlCommand(strSQL, cnnNwind)
cmdUpdates.CommandType = Data.CommandType.Text

cmdUpdates.CommandText = strSQL

intRecordsAffected = cmdUpdates.ExecuteNonQuery


End If

Catch exc As Exception
MsgBox(exc.Message + exc.StackTrace)


Finally

'Close the SqlConnection
cnnNwind.Close()


End Try

Reply With Quote
  #2 (permalink)  
Old June 23rd, 2006, 10:25 AM
Authorized User
 
Join Date: Jun 2006
Location: Manchester, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi There,

You do need to use javascript to display a simple message box. The main reason is that (I think I am right, I mainly code in c#) the MsgBox function you are using creates a dialogue that is meant for Windows Forms applications, rather than an ASP.NET application. Hence (again I think) that it will only work on machines that have the .net framework installed.

You could use VBScript (Client Script) to present a dialogue to the user, but as VBScript is not a web standard, but a Microsoft language, not all browsers support it.

So javascript is the best option. To do this you can simply Response.Write the piece of javascript you want to execute (in this case an alert box). This will then execute immediately on the clients web browser.

To do this use the javascript alert function:

Response.Write(String.Format("<script type='text/javascript'>alert('{0}');</script>", exc.Message + exc.StackTrace))

If you replace you MsgBox line with the above, your code should work on any browser.

Hope this helps,
Richard Marriott.

Reply With Quote
  #3 (permalink)  
Old June 23rd, 2006, 11:43 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rich,
    I tried inserting the reponse.write javascript statement in my code-benhind page, but on entering an invalid value, i cannot see the exception handler execute the alert message being displayed on screen.
If i put a mormal Response.write("Hello"), then this message appears.

Alex

Reply With Quote
  #4 (permalink)  
Old June 24th, 2006, 03:48 AM
Authorized User
 
Join Date: Jun 2006
Location: Manchester, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alex,

Ok, its probably best in that case to use the ClientScriptManager of the Page object to register a script to run on startup if you exception occurs. To do this, use the following code:

Code:
Page.ClientScript.RegisterStartupScript(typeof(string), "MyStartupScript", String.Format("<script type='text/javascript'>alert('{0}');</script>", exc.Message + exc.StackTrace));
Hope this helps,
Rich

Reply With Quote
  #5 (permalink)  
Old June 24th, 2006, 05:23 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rich,
      I enetered the foll. line in the code-behind page:
Page.ClientScript.RegisterStartupScript(typeof(str ing), "MyStartupScript", String.Format("<script type='text/javascript'>alert('{0}');</script>", exc.Message + exc.StackTrace));

On compilation, it gives the 2 errors:
1) String is a 'class' type and cannot be used an an expression
2) '.' expected

Alex

Reply With Quote
  #6 (permalink)  
Old June 24th, 2006, 12:41 PM
Authorized User
 
Join Date: Jun 2006
Location: Manchester, , United Kingdom.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Alex,

Apologies, I sent you c# code - me getting mixed up! Here is the VB.Net equivalent:

Code:
Page.ClientScript.RegisterStartupScript(GetType(String), "MyStartupScript", String.Format("<script type='text/javascript'>alert('{0}');</script>", exc.Message + exc.StackTrace))
Rich

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying < and > in browser csummers XSLT 1 January 24th, 2008 08:49 PM
web control not displaying in browser rj1406 ASP.NET 1.0 and 1.1 Basics 8 September 19th, 2004 05:32 AM
Displaying Excel in Browser sundar_revathi General .NET 0 July 7th, 2004 03:17 PM
please help ping from client browser nlicata Javascript 1 June 10th, 2004 12:23 PM
please help ping from client browser nlicata Javascript How-To 0 June 10th, 2004 01:46 AM



All times are GMT -4. The time now is 06:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.