Object Expected???

J

JLuv

I have a javascript function defined in my <head> tag on my ASP.NET
page. In the code-behind i have the lines...

void pGrid_DeleteCommand(object source, DataGridCommandEventArgs e)
{
string fName, lName;
fName = e.Item.Cells[5].Text.Trim();
lName = e.Item.Cells[4].Text.Trim();
Response.Write("<script language=javascript>confirmDelete('" +
fName + "', '" + lName + "')</script>");
if (hdnDelete.Value == "true")
//do stuff
}


confirmDelete() looks like this...

function confirmDelete(fName, lName)
{
if(confirm('Delete ' + fName + ' ' + lName + '?'))
{
document.form1.hdnDelete.Value = 'true';
alert(document.form1.hdnDelete.Value); //returns 'true'
like its suppose to.
}
else
{
document.form1.hdnDelete.Value = 'false';
}
}

However, whenever i trigger the event that holds the Response.Write(),
i get the "Object Expected" error.
Any help?
 
R

Richard Cornford

JLuv said:
I have a javascript function defined in my <head> tag on my
ASP.NET page. In the code-behind i have the lines...

ASP.NET terminology has very little relation to what browsers actually
do when attempting to execute javascript.

confirmDelete() looks like this...

function confirmDelete(fName, lName)
{
if(confirm('Delete ' + fName + ' ' + lName + '?'))
{
document.form1.hdnDelete.Value = 'true';

If this is supposed to be writing to the value property of a form
control (as appears to be the case) then in case-sensitive javascript
'Value' should be 'value'

However, whenever i trigger the event that holds the
Response.Write(), i get the "Object Expected" error.
Any help?

Use the view-source features of the browser to examine the HTML and
javascript actually sent to the browser, and verify that the browser is
actually getting the code you think it should be being sent (though that
doesn't help much unless you know what ASP.NET should be outputting, and
..NET tends to shield its users from understanding how it actually
works).

Richard.
 
R

Randy Webb

JLuv said the following on 8/11/2006 3:09 PM:
I have a javascript function defined in my <head> tag on my ASP.NET
page. In the code-behind i have the lines...

What's in your "code-behind" is 100% totally irrelevant to debugging
client side script errors.

However, whenever i trigger the event that holds the Response.Write(),
i get the "Object Expected" error.
Any help?

Post the HTML that the browser gets. You get 10-1 odds you are trying to
call your function before it gets defined:

someFunction()
function someFunction(){}

will result in an object expected error in IE.
 
J

JLuv

I just thought that where i defined and called the function in
code-behind had something to do with it.

You are right. When I look at the HTML the 1st line is the function
call and 25 lines later is the definition.

Now the question is how do I make sure that the function is called in
the correct place?
 
R

Randy Webb

JLuv said the following on 8/11/2006 5:38 PM:
I just thought that where i defined and called the function in
code-behind had something to do with it.

No. Well, it does in a way. Your code-behind is what generates what the
browser gets and since it has to be in a particular order in the
browser, then your code-behind is generating it in the wrong order.
You are right. When I look at the HTML the 1st line is the function
call and 25 lines later is the definition.

How did I guess that? said:
Now the question is how do I make sure that the function is called in
the correct place?

About the same way you *should* reply to Usenet postings. You make sure
the call to the function is after the function declaration. Or, you use
the onload of the window to call it. Much the same way you should make
sure that what you are replying with is after what you are replying to.
 
M

Michael Winter

On 11/08/2006 21:45, Randy Webb wrote:

[snip]
someFunction()
function someFunction(){}

will result in an object expected error in IE.

Only if the function declaration is in a separate script element that
follows the one containing the call. If both the call and the
declaration are contained in the same script element, or the declaration
appears in a preceding element, then there will be no error. MSIE would
be rather broken if that wasn't the case (yes, I know; it's broken
anyway :).

Mike
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,180
Latest member
CryptoTax Software
Top