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

June 23rd, 2006, 07:46 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 23rd, 2006, 10:25 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 23rd, 2006, 11:43 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 24th, 2006, 03:48 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 24th, 2006, 05:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 24th, 2006, 12:41 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |