Home All Groups Group Topic Archive Search About
Author
6 Jan 2006 10:12 AM
Kiyomi
Hello,



I am trying to replace my alert message box with a popup page.



In my page behind,

Response.Write("<script> alert('" & MyMsg & "') </script>")

is working fine.



I created a javascript function DoDialog() in the HTML part of the same page
and tried to run it with

Response.Write("<script language='javascript'> doDialog() </script>")



Then I get Object Expected error.  This code and the function are both on
the same page, and the name of the function is spelled out correctly.  I
tried to put my function in an external file .js but the result was the same
(Object Expected).



On the other hand, when I call the same function within HTML page with
onclick="doDialog()", it works fine.  If I call it from code behind page
using Button.Attributes.Add("onclick", "doDialog()") it works fine too.



Why this function cannot be recognised in Response.write?  In fact, I cannot
use "onclick" to call this function because I have some complex checks to do
on the code behind page (using select case, different stored procedures,
etc.) after clicking the button and before running this function.

Author
6 Jan 2006 3:11 PM
Marina
javascript is case sensitive. If the function is called DoDialog, that is
how you have to call it.

Also, if the code to run the function is streamed out before the function
itself, then the engine will not be able to find the function. But you
didn't post your page code, so it's really just a guess.

Show quoteHide quote
"Kiyomi" <k.kana***@unesco.org> wrote in message
news:e5pXAnqEGHA.868@TK2MSFTNGP10.phx.gbl...
> Hello,
>
>
>
> I am trying to replace my alert message box with a popup page.
>
>
>
> In my page behind,
>
> Response.Write("<script> alert('" & MyMsg & "') </script>")
>
> is working fine.
>
>
>
> I created a javascript function DoDialog() in the HTML part of the same
> page
> and tried to run it with
>
> Response.Write("<script language='javascript'> doDialog() </script>")
>
>
>
> Then I get Object Expected error.  This code and the function are both on
> the same page, and the name of the function is spelled out correctly.  I
> tried to put my function in an external file .js but the result was the
> same
> (Object Expected).
>
>
>
> On the other hand, when I call the same function within HTML page with
> onclick="doDialog()", it works fine.  If I call it from code behind page
> using Button.Attributes.Add("onclick", "doDialog()") it works fine too.
>
>
>
> Why this function cannot be recognised in Response.write?  In fact, I
> cannot
> use "onclick" to call this function because I have some complex checks to
> do
> on the code behind page (using select case, different stored procedures,
> etc.) after clicking the button and before running this function.
>
>
>
Are all your drivers up to date? click for free checkup

Author
6 Jan 2006 5:03 PM
Kiyomi
Here is my HTML page.  I would very much appreciate your advice.
<input onclick="doDialog()" > works well, but this is not really what I
really need.
I wish to call doDialog() from different places in the code behind page, for
example, using Response.Write("<script language='javascript'> doDialog()
</script>")

Thank you.

<HTML>
<HEAD>
    <SCRIPT language="javascript">
        function doDialog()
        {if (Form1.textError.value != "")
            {
                var x=showModalDialog('dcontents.htm', Form1.txtError.value,
'status:no;resizable:yes');
                d1.innerHTML="The dialog box return value was: " + x;
            }
        }
    </SCRIPT>
</HEAD>

<body>
    <form id="Form1" method="post" runat="server">
    <P>Enter your age :
            <asp:textbox id="txtInput" runat="server"></asp:txtbox></P>
    <P>
            <asp:button id="Button2" runat="server"
Text="OK"></asp:button></P>
    <P>
            <asp:label id="lblError runat="server"
ForeColor="Red"></asp:label></P>
            <asp:label id="lblConfirm runat="server"
ForeColor="Green"></asp:label></P>
    <P>
             <asp:rextbox id="txtError runat="server"></asp:textbox></P>
    <P>
            <input onclick="doDialog()" type="button" value="Create
Dialog"></P>
    <DIV id=d1></DIV>
    </form>
</body>
</HTML>



Show quoteHide quote
"Marina" <someone@nospam.com> wrote in message
news:uB2GKOtEGHA.2708@TK2MSFTNGP11.phx.gbl...
> javascript is case sensitive. If the function is called DoDialog, that is
> how you have to call it.
>
> Also, if the code to run the function is streamed out before the function
> itself, then the engine will not be able to find the function. But you
> didn't post your page code, so it's really just a guess.
>
> "Kiyomi" <k.kana***@unesco.org> wrote in message
> news:e5pXAnqEGHA.868@TK2MSFTNGP10.phx.gbl...
> > Hello,
> >
> >
> >
> > I am trying to replace my alert message box with a popup page.
> >
> >
> >
> > In my page behind,
> >
> > Response.Write("<script> alert('" & MyMsg & "') </script>")
> >
> > is working fine.
> >
> >
> >
> > I created a javascript function DoDialog() in the HTML part of the same
> > page
> > and tried to run it with
> >
> > Response.Write("<script language='javascript'> doDialog() </script>")
> >
> >
> >
> > Then I get Object Expected error.  This code and the function are both
on
> > the same page, and the name of the function is spelled out correctly.  I
> > tried to put my function in an external file .js but the result was the
> > same
> > (Object Expected).
> >
> >
> >
> > On the other hand, when I call the same function within HTML page with
> > onclick="doDialog()", it works fine.  If I call it from code behind page
> > using Button.Attributes.Add("onclick", "doDialog()") it works fine too.
> >
> >
> >
> > Why this function cannot be recognised in Response.write?  In fact, I
> > cannot
> > use "onclick" to call this function because I have some complex checks
to
> > do
> > on the code behind page (using select case, different stored procedures,
> > etc.) after clicking the button and before running this function.
> >
> >
> >
>
>
Author
6 Jan 2006 5:09 PM
Marina
You showed the source code for your page - but not the page as it is when
streamed down as HTML.

Your Response.Write is writing out the call to doDialog at the very top of
the page. The function does not get declared until the <head> element. So
the problem is that you are trying to call a function that javascript does
not know about yet (this is what I suggested in the first post).  I suspect
that this is the order that everything is getting streamed out as.

In which case, don't use Response.Write to stream the script out at the very
top of the page. Embed it someplace else after the head element.

Show quoteHide quote
"Kiyomi" <k.kana***@unesco.org> wrote in message
news:eB75dMuEGHA.3984@TK2MSFTNGP14.phx.gbl...
> Here is my HTML page.  I would very much appreciate your advice.
> <input onclick="doDialog()" > works well, but this is not really what I
> really need.
> I wish to call doDialog() from different places in the code behind page,
> for
> example, using Response.Write("<script language='javascript'> doDialog()
> </script>")
>
> Thank you.
>
> <HTML>
> <HEAD>
>    <SCRIPT language="javascript">
>        function doDialog()
>        {if (Form1.textError.value != "")
>            {
>                var x=showModalDialog('dcontents.htm',
> Form1.txtError.value,
> 'status:no;resizable:yes');
>                d1.innerHTML="The dialog box return value was: " + x;
>            }
>        }
>    </SCRIPT>
> </HEAD>
>
> <body>
>    <form id="Form1" method="post" runat="server">
>    <P>Enter your age :
>            <asp:textbox id="txtInput" runat="server"></asp:txtbox></P>
>    <P>
>            <asp:button id="Button2" runat="server"
> Text="OK"></asp:button></P>
>    <P>
>            <asp:label id="lblError runat="server"
> ForeColor="Red"></asp:label></P>
>            <asp:label id="lblConfirm runat="server"
> ForeColor="Green"></asp:label></P>
>    <P>
>             <asp:rextbox id="txtError runat="server"></asp:textbox></P>
>    <P>
>            <input onclick="doDialog()" type="button" value="Create
> Dialog"></P>
>    <DIV id=d1></DIV>
>    </form>
> </body>
> </HTML>
>
>
>
> "Marina" <someone@nospam.com> wrote in message
> news:uB2GKOtEGHA.2708@TK2MSFTNGP11.phx.gbl...
>> javascript is case sensitive. If the function is called DoDialog, that is
>> how you have to call it.
>>
>> Also, if the code to run the function is streamed out before the function
>> itself, then the engine will not be able to find the function. But you
>> didn't post your page code, so it's really just a guess.
>>
>> "Kiyomi" <k.kana***@unesco.org> wrote in message
>> news:e5pXAnqEGHA.868@TK2MSFTNGP10.phx.gbl...
>> > Hello,
>> >
>> >
>> >
>> > I am trying to replace my alert message box with a popup page.
>> >
>> >
>> >
>> > In my page behind,
>> >
>> > Response.Write("<script> alert('" & MyMsg & "') </script>")
>> >
>> > is working fine.
>> >
>> >
>> >
>> > I created a javascript function DoDialog() in the HTML part of the same
>> > page
>> > and tried to run it with
>> >
>> > Response.Write("<script language='javascript'> doDialog() </script>")
>> >
>> >
>> >
>> > Then I get Object Expected error.  This code and the function are both
> on
>> > the same page, and the name of the function is spelled out correctly.
>> > I
>> > tried to put my function in an external file .js but the result was the
>> > same
>> > (Object Expected).
>> >
>> >
>> >
>> > On the other hand, when I call the same function within HTML page with
>> > onclick="doDialog()", it works fine.  If I call it from code behind
>> > page
>> > using Button.Attributes.Add("onclick", "doDialog()") it works fine too.
>> >
>> >
>> >
>> > Why this function cannot be recognised in Response.write?  In fact, I
>> > cannot
>> > use "onclick" to call this function because I have some complex checks
> to
>> > do
>> > on the code behind page (using select case, different stored
>> > procedures,
>> > etc.) after clicking the button and before running this function.
>> >
>> >
>> >
>>
>>
>
>
Author
10 Jan 2006 4:31 PM
Kiyomi
Thank you very much, Marina, for your advice.
I managed to make my popup work, using RegisterStartupScript as follows.
Now, I wish to retrieve user's response (OK or Cancel) and, depending on the
response, I wish to continue different processes.
Would you please advice me how I can do this ?

Thank you very much.


************* HTML page *************

function doConfirm(msg) {
    var x=showModalDialog('Confirm.htm', msg, 'status:no;resizable:yes');
    }


************* VB code behind page *************

Function CheckRules()

    Dim msg as String
    msg = "An error is detected.  Do you want to continue processing ? "

    If (Not Me.IsStartupScriptRegistered("Startup")) Then
       Me.RegisterStartupScript("Startup", "<script>doConfirm('" & msg &
        "');</script>")
    End If

----- After running doConfirm(msg), this is what I wish to do --------

    If doConfirm(msg) returns True (i.e., user clicks OK button)
            Continue processing below
    Else (i.e., user clicks Cancel button)
            Return False
            Exit Function
    End if

----- Continue processing

    Return True

End Function


Show quoteHide quote
"Marina" <someone@nospam.com> wrote in message
news:ucfKsPuEGHA.376@TK2MSFTNGP12.phx.gbl...
> You showed the source code for your page - but not the page as it is when
> streamed down as HTML.
>
> Your Response.Write is writing out the call to doDialog at the very top of
> the page. The function does not get declared until the <head> element. So
> the problem is that you are trying to call a function that javascript does
> not know about yet (this is what I suggested in the first post).  I
suspect
> that this is the order that everything is getting streamed out as.
>
> In which case, don't use Response.Write to stream the script out at the
very
> top of the page. Embed it someplace else after the head element.
>
> "Kiyomi" <k.kana***@unesco.org> wrote in message
> news:eB75dMuEGHA.3984@TK2MSFTNGP14.phx.gbl...
> > Here is my HTML page.  I would very much appreciate your advice.
> > <input onclick="doDialog()" > works well, but this is not really what I
> > really need.
> > I wish to call doDialog() from different places in the code behind page,
> > for
> > example, using Response.Write("<script language='javascript'> doDialog()
> > </script>")
> >
> > Thank you.
> >
> > <HTML>
> > <HEAD>
> >    <SCRIPT language="javascript">
> >        function doDialog()
> >        {if (Form1.textError.value != "")
> >            {
> >                var x=showModalDialog('dcontents.htm',
> > Form1.txtError.value,
> > 'status:no;resizable:yes');
> >                d1.innerHTML="The dialog box return value was: " + x;
> >            }
> >        }
> >    </SCRIPT>
> > </HEAD>
> >
> > <body>
> >    <form id="Form1" method="post" runat="server">
> >    <P>Enter your age :
> >            <asp:textbox id="txtInput" runat="server"></asp:txtbox></P>
> >    <P>
> >            <asp:button id="Button2" runat="server"
> > Text="OK"></asp:button></P>
> >    <P>
> >            <asp:label id="lblError runat="server"
> > ForeColor="Red"></asp:label></P>
> >            <asp:label id="lblConfirm runat="server"
> > ForeColor="Green"></asp:label></P>
> >    <P>
> >             <asp:rextbox id="txtError runat="server"></asp:textbox></P>
> >    <P>
> >            <input onclick="doDialog()" type="button" value="Create
> > Dialog"></P>
> >    <DIV id=d1></DIV>
> >    </form>
> > </body>
> > </HTML>
> >
> >
> >
> > "Marina" <someone@nospam.com> wrote in message
> > news:uB2GKOtEGHA.2708@TK2MSFTNGP11.phx.gbl...
> >> javascript is case sensitive. If the function is called DoDialog, that
is
> >> how you have to call it.
> >>
> >> Also, if the code to run the function is streamed out before the
function
> >> itself, then the engine will not be able to find the function. But you
> >> didn't post your page code, so it's really just a guess.
> >>
> >> "Kiyomi" <k.kana***@unesco.org> wrote in message
> >> news:e5pXAnqEGHA.868@TK2MSFTNGP10.phx.gbl...
> >> > Hello,
> >> >
> >> >
> >> >
> >> > I am trying to replace my alert message box with a popup page.
> >> >
> >> >
> >> >
> >> > In my page behind,
> >> >
> >> > Response.Write("<script> alert('" & MyMsg & "') </script>")
> >> >
> >> > is working fine.
> >> >
> >> >
> >> >
> >> > I created a javascript function DoDialog() in the HTML part of the
same
> >> > page
> >> > and tried to run it with
> >> >
> >> > Response.Write("<script language='javascript'> doDialog() </script>")
> >> >
> >> >
> >> >
> >> > Then I get Object Expected error.  This code and the function are
both
> > on
> >> > the same page, and the name of the function is spelled out correctly.
> >> > I
> >> > tried to put my function in an external file .js but the result was
the
> >> > same
> >> > (Object Expected).
> >> >
> >> >
> >> >
> >> > On the other hand, when I call the same function within HTML page
with
> >> > onclick="doDialog()", it works fine.  If I call it from code behind
> >> > page
> >> > using Button.Attributes.Add("onclick", "doDialog()") it works fine
too.
> >> >
> >> >
> >> >
> >> > Why this function cannot be recognised in Response.write?  In fact, I
> >> > cannot
> >> > use "onclick" to call this function because I have some complex
checks
> > to
> >> > do
> >> > on the code behind page (using select case, different stored
> >> > procedures,
> >> > etc.) after clicking the button and before running this function.
> >> >
> >> >
> >> >
> >>
> >>
> >
> >
>
>

Bookmark and Share