Script Problem

W

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 &amp;
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
 
K

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
 
W

Wayne Wengert

Thanks Karl. Let me experiment with that.

Wayne

Karl said:
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
 
W

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
 
K

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
 
W

Wayne Wengert

Karl;

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

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top