By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Object Expected error

P: n/a
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.

Jan 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Would you be able to post the actual HTML submitted to the client when this
'Response.Write' is executed. I am interested in seeing where the actual
output exists within the HTML. You may find that you can fix this by changing
the location that your script ends up in the output HTML document.

Otherwise, you might also be able to try something like...

<script language=javascript>window.onload=doDialog();</script>

That way, this will get called by the client-side event when the page is
loaded.

Hope this helps,

-Eric
"Kiyomi" wrote:
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.

Jan 6 '06 #2

P: n/a
Thank you, Eric.

I tried to place window.onload=doDialog(); right after </body> and it looks
working exactly as I wish.

However, I got another error Not Implemented on that line.

Here is my HTML for your reference.

Thank you again for your help,

Kiyomi

<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>
"Eric Giles" <Er*******@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Would you be able to post the actual HTML submitted to the client when this 'Response.Write' is executed. I am interested in seeing where the actual
output exists within the HTML. You may find that you can fix this by changing the location that your script ends up in the output HTML document.

Otherwise, you might also be able to try something like...

<script language=javascript>window.onload=doDialog();</script>

That way, this will get called by the client-side event when the page is
loaded.

Hope this helps,

-Eric
"Kiyomi" wrote:
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.

Jan 6 '06 #3

P: n/a
There seems to be a problem with your HTML.

Check the line.

<asp:rextbox id="txtError runat="server"></asp:textbox>

Should be

<asp:textbox id="txtError" runat="server"></asp:textbox>

Perhaps it cannot find it because it is not created correctly.

Might be worth checking.

-Eric
"Kiyomi" wrote:
Thank you, Eric.

I tried to place window.onload=doDialog(); right after </body> and it looks
working exactly as I wish.

However, I got another error Not Implemented on that line.

Here is my HTML for your reference.

Thank you again for your help,

Kiyomi

<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>
"Eric Giles" <Er*******@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Would you be able to post the actual HTML submitted to the client when

this
'Response.Write' is executed. I am interested in seeing where the actual
output exists within the HTML. You may find that you can fix this by

changing
the location that your script ends up in the output HTML document.

Otherwise, you might also be able to try something like...

<script language=javascript>window.onload=doDialog();</script>

That way, this will get called by the client-side event when the page is
loaded.

Hope this helps,

-Eric
"Kiyomi" wrote:
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.


Jan 7 '06 #4

P: n/a
Thank you very much, Eric, 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


"Eric Giles" <Er*******@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
There seems to be a problem with your HTML.

Check the line.

<asp:rextbox id="txtError runat="server"></asp:textbox>

Should be

<asp:textbox id="txtError" runat="server"></asp:textbox>

Perhaps it cannot find it because it is not created correctly.

Might be worth checking.

-Eric
"Kiyomi" wrote:
Thank you, Eric.

I tried to place window.onload=doDialog(); right after </body> and it looks working exactly as I wish.

However, I got another error Not Implemented on that line.

Here is my HTML for your reference.

Thank you again for your help,

Kiyomi

<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>
"Eric Giles" <Er*******@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Would you be able to post the actual HTML submitted to the client when

this
'Response.Write' is executed. I am interested in seeing where the actual output exists within the HTML. You may find that you can fix this by

changing
the location that your script ends up in the output HTML document.

Otherwise, you might also be able to try something like...

<script language=javascript>window.onload=doDialog();</script>

That way, this will get called by the client-side event when the page is loaded.

Hope this helps,

-Eric
"Kiyomi" wrote:

> 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.
>
>
>
>


Jan 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.