Re: Script Problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Karl (_at_)
Date: 09/15/04


Date: Tue, 14 Sep 2004 20:55:23 -0400

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" <wayneDONTWANTSPAM@wengert.com> wrote in message
news:uxvD19qmEHA.1712@TK2MSFTNGP09.phx.gbl...
> 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
>
>

Quantcast