Re: Script Problem
From: Wayne Wengert (wayneDONTWANTSPAM_at_wengert.com)
Date: 09/15/04
- Next message: news_at_visual-basic-data-mining.net: "Re: Displaying image after selecting an image file."
- Previous message: DaveF: "how to check for bounced email?"
- Maybe in reply to: Wayne Wengert: "Script Problem"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 15 Sep 2004 17:22:43 -0600
Thanks for all the help and education - I will go back and do more reading
and then see if I can work things out.
Again - I appreciate all your time.
Wayne
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uAHIap3mEHA.2892@TK2MSFTNGP10.phx.gbl...
> No. I thin it's important that you understand what's happenig - as it
seems
> like you don't.
>
> When the button is clicked, the page is reloaded, Page_Load is executed,
> the then Button's event handler (btnSave_Click) is executed. This method
> calls DisplayAlert. Hopefully so far so good. In DisplayAlert (here's
> where I think you might be confused) you call RegisterClientScriptBlock.
> What RegisterClientScriptBlock does is it outputs javascript at the end of
> the request. But remember, you are still processing the event being
clicked
> (ie, you are still on the server-side). For the javascript to work you
need
> to send the response to the client, which will render the html and execute
> any javascript. However, you are doing a server.transfer...effectively
> killing the response and starting a new.
> The trick would be to make the page you are transfering to display the
> alert.
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Wayne Wengert" <wayneDONTWANTSPAM@wengert.com> wrote in message
> news:OWj0Qf3mEHA.2680@TK2MSFTNGP15.phx.gbl...
> > Duh!!! Sorry about that. I did find what is happening (I think!)
> >
> > Immediately after displaying the alert I do a Server.Transfer to go back
> to
> > a selection page. If I comment out the server.transfer I see the alert
> box.
> > It appears that the alert doesn't execute before the server.transfer? Is
> > there a way to get it to wait until the alert displays and the used
clicks
> > OK?
> >
> > Wayne
> >
> > "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote
in
> > message news:%23XpnCl2mEHA.1248@TK2MSFTNGP09.phx.gbl...
> > > Well DisplayAlert outputs javascript to the browser...so when the page
> is
> > > reloaded, go "view source" in the page and look for:
> > > alert('The information has been added to the database!');
> > >
> > > Karl
> > >
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "Wayne Wengert" <wayneDONTWANTSPAM@wengert.com> wrote in message
> > > news:OppLqeymEHA.2764@TK2MSFTNGP11.phx.gbl...
> > > > 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:eaFtGAymEHA.3632@TK2MSFTNGP09.phx.gbl...
> > > > > 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" <wayneDONTWANTSPAM@wengert.com> wrote in message
> > > > > news:%233knWiwmEHA.1712@TK2MSFTNGP09.phx.gbl...
> > > > > > 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:O6N5n2rmEHA.392@tk2msftngp13.phx.gbl...
> > > > > > > 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
> &
> > > > > > > > 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
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: news_at_visual-basic-data-mining.net: "Re: Displaying image after selecting an image file."
- Previous message: DaveF: "how to check for bounced email?"
- Maybe in reply to: Wayne Wengert: "Script Problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|