.NETGURU
Script Problem
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.

Post a new message to this list...

Wayne Wengert
I am attempting to incorporate some techniques I found in an MSDN article
into one of my aspx pages. It basically adds a new class that Inherits from
the System.Web.UI.Page and includes some new subs and function (some are
shown below). I have a page based on that new class and in my code where a
user clicks on a Save button (saves data to my DB) I want to display an
alert message. I get the error indicated below when I run the page - I
assume it has to do with the onclick event which calls sub in the base
class? How should this be coded?

Wayne

============= Error Information ============
Compiler Error Message: BC30201: Expression expected.

Source Error:

Line 30:                 <asp:textbox id="txtMisc" style="Z-INDEX: 117; LEFT: 133px;
POSITION: absolute; TOP: 497px" runat="server"
Line 31:                 Width="475px" Height="56px" MaxLength="200"
TextMode="MultiLine" Rows="2"></asp:textbox>
Line 32:                 <asp:button id="btnSave" style="Z-INDEX: 118; LEFT: 159px;
POSITION: absolute; TOP: 564px" runat="server"
Line 33:                 Width="100px" Height="29px" onclick="DisplayAlert('The
information has been added to the database!')" Text="Save &
Exit"></asp:button>
Line 34:                 <asp:button id="btnCancel" style="Z-INDEX: 119; LEFT: 348px;
POSITION: absolute; TOP: 565px"

============= In Class Inherited ==============
Public Sub DisplayAlert(ByVal message As String)

RegisterClientScriptBlock(Guid.NewGuid().ToString(), _

"<script language=""JavaScript"">" & GetAlertScript(message) & "</script>")

End Sub

Public Function GetAlertScript(ByVal message As String) As String

Return "alert('" & message.Replace("'", "\'") & "');"

End Function

Reply to this message...
 
    
Karl
The OnClick method of the Button calls an EventHandler...try to modify your
code like so (i got rid of the style stuff just to help readability, you can
safely put it in)

<asp:button id="btnSave" runat="server" CommandArgument="'The information
has been added to the database" onclick="save_click" Text="Save" />

and the method:

Protected Sub Save_Click(ByVal sender As Object, ByVal e As EventArgs)
DisplayAlert(CType(sender, Button).CommandArgument)
End Sub

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Wayne Wengert" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Wayne Wengert
Thanks Karl. Let me experiment with that.

Wayne

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:Click here to reveal e-mail address...
> The OnClick method of the Button calls an EventHandler...try to modify
your
> code like so (i got rid of the style stuff just to help readability, you
can
[Original message clipped]

Reply to this message...
 
    
Wayne Wengert
I tried adding the code:

DisplayAlert("The information has been added to the database!")

in the btnSave_Click event but although I can verify that the code is being
executed the alert never shows?

Wayne

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:Click here to reveal e-mail address...
> The OnClick method of the Button calls an EventHandler...try to modify
your
> code like so (i got rid of the style stuff just to help readability, you
can
[Original message clipped]

Reply to this message...
 
    
Karl
That's odd, I tried it out and got it working before posting you the
solution.

Can you confirm that the javascript is being rendered on the page?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Wayne Wengert" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Wayne Wengert
Karl;

How can I confirm that? I did put in a breakpoint and I know the
DisplayAlert code is executed?

Wayne

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.EventHandler
System.Guid
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification