Wrox Programmer Forums
|
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
 
Old February 13th, 2009, 03:02 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Question Use of ASPNET_MsgBox

In my application I am using

Code:
 
Public Sub ASPNET_MsgBox(ByVal Message As String)
Page.ClientScript.RegisterStartupScript(Page.GetType(), Guid.NewGuid().ToString(), "alert(""" & Message & """)", True)
End Sub
and it works fine. My question is: When passing a message to the sub and the message is very long, how can I tell the JavaScript to write multiple lines. Can I put "skip to new line" in the message string?

Code:
 
Catch ex As Exception
ErrorString = ex.ToString
ASPNET_MsgBox("An error has occurred. Contact your IT department: " + ErrorString)
 
Old February 16th, 2009, 01:23 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You could achieve this with a function similar to this (this is off the cuff so if might do with a bit of refactoring / optimization)

for the sake of example, lets say that you want to insert a new line character after every fifteen characters, you would do something like this:

vb Code:
Private Function ParseJavaScriptString(value as String) As String
     Dim charArray() as Char = value.ToCharArray()
     For i as Integer = 0 to charArray.Length Step 1 
         'You need to add 1 to your current value since we are working off of a Zero Based index
         If (i + 1) Mod = 15 then value.Insert(i, "\n")
     Loop
End Function

This of course does not take phonetics into account so, for example, take the string: The sky is extremly blue today.

Your alert would display that as:
The sky is extr
mly blue today.

You could modify the above function to workin something like:

vb Code:
Private Function ParseJavaScriptString(value as String) As String
     Dim charArray() as Char = value.ToCharArray()
     Dim blnIsSpace as Boolean = True
     For i as Integer = 0 to charArray.Length Step 1 
         If blnIsSpace
              If (i + 1) Mod = 15 AND charArray(i).Equals(" ")  then value.Insert(i, "\n")
              else blnIsSpace = False
         Else
              If charArray(i).Equals(" ") Then
                   value.Insert(i, "\n")
                   blnIsSpace = True
              End If
         End If
     Loop
End Function

Obviously you are not going to get perfectly even lines since line 1 might contain 15 characters will line 2 contains 17 and so on. It all depends on where a space falls at within the string.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old February 16th, 2009, 01:25 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Oops! Don't forget to return the variable 'value' from your function.
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPNET_MsgBox - confirm snufse ASP.NET 2.0 Basics 2 January 19th, 2009 05:48 PM
[Resolved] ASPNET_MsgBox hides grid view snufse ASP.NET 2.0 Basics 2 October 9th, 2008 01:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.