imrancs
asked on
display alert in asp.net web service
Hi Experts
I want to display alert in asp.net web service how can i do this currently i am displaying alert by following code but it generates error "This is an unexpected token. The expected token is 'QUOTE'."
Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
System.Web.HttpContext.Cur rent.Respo nse.Write( str)
it very urgent.
Thanks,
Ahmad
I want to display alert in asp.net web service how can i do this currently i am displaying alert by following code but it generates error "This is an unexpected token. The expected token is 'QUOTE'."
Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
System.Web.HttpContext.Cur
it very urgent.
Thanks,
Ahmad
ASKER
Hi mmarinov
I run some store procedure in web service which take 5 to 10 minutes so after finish it i need to display some message to client. these procedure calls in thread so user can do some other task during the process of these procedure.
thanks,
ahmad
I run some store procedure in web service which take 5 to 10 minutes so after finish it i need to display some message to client. these procedure calls in thread so user can do some other task during the process of these procedure.
thanks,
ahmad
why don't you use async requests to the web service. (using async pages in 2.0 or using ajax in 1.1 and 2.0)
check these links
http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/
http://www.informit.com/articles/article.asp?p=174363&seqNum=2&rl=1
http://www.theserverside.net/discussions/thread.tss?thread_id=35834
regards
check these links
http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/
http://www.informit.com/articles/article.asp?p=174363&seqNum=2&rl=1
http://www.theserverside.net/discussions/thread.tss?thread_id=35834
regards
ASKER
i try it after that i will response back you
Try this
<WebMethod()> _
Public Sub GetStringAndShowAlert(ByVa l strAlert As String)
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder( )
sScript.Append("<HTML><HEA D> ")
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi s is the input string: " + strAlert + "');")
sScript.Append("}")
sScript.Append("</script>" )
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H TML>")
System.Web.HttpContext.Cur rent.Respo nse.Write( sScript.To String())
End Sub
<WebMethod()> _
Public Sub GetStringAndShowAlert(ByVa
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder(
sScript.Append("<HTML><HEA
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi
sScript.Append("}")
sScript.Append("</script>"
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H
System.Web.HttpContext.Cur
End Sub
ASKER
Hi Codeclay
I am getting following error.
The <HTML> tag from namespace is not expected.
how to resolve it.
thanks,
ahmad
I am getting following error.
The <HTML> tag from namespace is not expected.
how to resolve it.
thanks,
ahmad
It works fine for me . Did u try using the webmethod mentioned above in a new webservice ? Also could you post your code here?
ASKER
it works fine in web service but when i call it from the application then it generates error
Here are code
Calling from Application
Dim obj As New localhost.TemplateService
Try
obj.GetStringAndShowAlert( "Test")
Catch ex As Exception
End Try
Web Service Code
Imports System.Web.Services
'Imports System.Threading
<System.Web.Services.WebSe rvice(Name space:="http://tempuri.org/TemplateService/TemplateService") > _
Public Class TemplateService
Inherits System.Web.Services.WebSer vice
'Private objThread As Thread
'Dim obj As Object
'Dim objApp As Object
'Dim DataBaseName As String
'Dim xmlFileName As String = "../Databases.xml"
'Dim BContract, BTemplate As Boolean
'Dim SPage As Integer
#Region " Web Services Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
components = New System.ComponentModel.Cont ainer
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
' WEB SERVICE EXAMPLE
' The HelloWorld() example service returns the string Hello World.
' To build, uncomment the following lines then save and build the project.
' To test this web service, ensure that the .asmx file is the start page
' and press F5.
'
'<WebMethod()> _
' <WebMethod()> _
' Public Sub UpdateAllDetailsSection(By Ref DBName As String, ByVal BIsTemplate As Boolean, ByVal BIsContract As Boolean)
' BContract = BIsContract
' BTemplate = BIsTemplate
' DataBaseName = DBName
' obj = System.Web.HttpContext.Cur rent.Serve r.MapPath( xmlFileNam e)
' Me.objThread = New Thread(AddressOf StartThread)
' objThread.Name = "Thread_1"
' Me.objThread.IsBackground = True
' Me.objThread.Start()
' 'Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
' 'System.Web.HttpContext.Cu rrent.Resp onse.Write (str)
' End Sub
' <WebMethod()> _
'Public Sub UpdateAllPagesSection(ByRe f DBName As String, ByVal BIsTemplate As Boolean, ByVal BIsContract As Boolean, ByVal SummaryPage As Integer)
' SPage = SummaryPage
' BContract = BIsContract
' BTemplate = BIsTemplate
' DataBaseName = DBName
' obj = System.Web.HttpContext.Cur rent.Serve r.MapPath( xmlFileNam e)
' Me.objThread = New Thread(AddressOf StartDetailThread)
' objThread.Name = "Thread_1"
' Me.objThread.IsBackground = True
' Me.objThread.Start()
' 'Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
' 'System.Web.HttpContext.Cu rrent.Resp onse.Write (str)
' End Sub
<WebMethod()> _
Public Sub GetStringAndShowAlert(ByVa l strAlert As String)
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder
sScript.Append("<HTML><HEA D> ")
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi s is the input string: " + strAlert + "');")
sScript.Append("}")
sScript.Append("</script>" )
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H TML>")
System.Web.HttpContext.Cur rent.Respo nse.Write( sScript.To String())
End Sub
'Public Sub StartDetailThread()
' Template.UpdateAllPages(Da taBaseName , obj, BTemplate, BContract, SPage)
' Me.objThread.Abort()
'End Sub
'Public Sub StartThread()
' Template.UpdateAllDetails( DataBaseNa me, obj, BTemplate, BContract)
' Me.objThread.Abort()
'End Sub
End Class
Here are code
Calling from Application
Dim obj As New localhost.TemplateService
Try
obj.GetStringAndShowAlert(
Catch ex As Exception
End Try
Web Service Code
Imports System.Web.Services
'Imports System.Threading
<System.Web.Services.WebSe
Public Class TemplateService
Inherits System.Web.Services.WebSer
'Private objThread As Thread
'Dim obj As Object
'Dim objApp As Object
'Dim DataBaseName As String
'Dim xmlFileName As String = "../Databases.xml"
'Dim BContract, BTemplate As Boolean
'Dim SPage As Integer
#Region " Web Services Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.Debugg
components = New System.ComponentModel.Cont
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#End Region
' WEB SERVICE EXAMPLE
' The HelloWorld() example service returns the string Hello World.
' To build, uncomment the following lines then save and build the project.
' To test this web service, ensure that the .asmx file is the start page
' and press F5.
'
'<WebMethod()> _
' <WebMethod()> _
' Public Sub UpdateAllDetailsSection(By
' BContract = BIsContract
' BTemplate = BIsTemplate
' DataBaseName = DBName
' obj = System.Web.HttpContext.Cur
' Me.objThread = New Thread(AddressOf StartThread)
' objThread.Name = "Thread_1"
' Me.objThread.IsBackground = True
' Me.objThread.Start()
' 'Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
' 'System.Web.HttpContext.Cu
' End Sub
' <WebMethod()> _
'Public Sub UpdateAllPagesSection(ByRe
' SPage = SummaryPage
' BContract = BIsContract
' BTemplate = BIsTemplate
' DataBaseName = DBName
' obj = System.Web.HttpContext.Cur
' Me.objThread = New Thread(AddressOf StartDetailThread)
' objThread.Name = "Thread_1"
' Me.objThread.IsBackground = True
' Me.objThread.Start()
' 'Dim str As String = "<script langugae=javascript> alert('Templates have been updated.'); </script>"
' 'System.Web.HttpContext.Cu
' End Sub
<WebMethod()> _
Public Sub GetStringAndShowAlert(ByVa
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder
sScript.Append("<HTML><HEA
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi
sScript.Append("}")
sScript.Append("</script>"
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H
System.Web.HttpContext.Cur
End Sub
'Public Sub StartDetailThread()
' Template.UpdateAllPages(Da
' Me.objThread.Abort()
'End Sub
'Public Sub StartThread()
' Template.UpdateAllDetails(
' Me.objThread.Abort()
'End Sub
End Class
Modify the GetStringAnd ShowAlert method as follows
Private Function GetStringAndShowAlert(ByVa l strAlert As String) As String
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder( )
sScript.Append("<HTML><HEA D> ")
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi s is the input string:" + strAlert + "');")
sScript.Append("}")
sScript.Append("</script>" )
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H TML>")
GetStringAndShowAlert= sScript.ToString()
End Function
From the application where you call this ,
Dim obj As New localhost.TemplateService
Try
Dim strText As String = obj.GetStringAndShowAlert( "Test")
Response.Write(strText)
Catch ex As Exception
End Try
Private Function GetStringAndShowAlert(ByVa
Dim sScript As System.Text.StringBuilder
sScript = New System.Text.StringBuilder(
sScript.Append("<HTML><HEA
sScript.Append("<script LANGUAGE='javascript'> ")
sScript.Append("function ShowMessage() { ")
sScript.Append("alert('Thi
sScript.Append("}")
sScript.Append("</script>"
sScript.Append("</HEAD>")
sScript.Append("<BODY onload=ShowMessage();>")
sScript.Append("</BODY></H
GetStringAndShowAlert= sScript.ToString()
End Function
From the application where you call this ,
Dim obj As New localhost.TemplateService
Try
Dim strText As String = obj.GetStringAndShowAlert(
Response.Write(strText)
Catch ex As Exception
End Try
ASKER
Hi Codeclay
it works fine if not put to in thread if put it into thread then it does not work fine. have you any solution for this?
thanks,
ahmad
it works fine if not put to in thread if put it into thread then it does not work fine. have you any solution for this?
thanks,
ahmad
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
regards