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

calling javascript function from asp.net

P: n/a
I have a piece of code that calls the clientside it works ok when no
values are passed ie window.alert ('this is a test'). But I have a
value from a textbox example:
function openemail()
{
var email = document.getElementbyID("txtEmailAddress").value;
window.alert(email);
}
when I call this function
string script = "<script language='javascript'>openemail();</script>";
Page.RegisterClientScriptBlock("email", script);
Its gives me an error saying missing object.
Any help will be greatly appreciated

Dec 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ki*************@consultant.com wrote:
I have a piece of code that calls the clientside it works ok when no
values are passed ie window.alert ('this is a test'). But I have a
value from a textbox example:
function openemail()
{
var email = document.getElementbyID("txtEmailAddress").value;
window.alert(email);
}
when I call this function
string script = "<script language='javascript'>openemail();</script>";
Page.RegisterClientScriptBlock("email", script);
Its gives me an error saying missing object.
Any help will be greatly appreciated
It is due to the fact that when the aspx page is rendered, your control
txtEmailAddress will have a more complicated id based on page id and
container control (if any).

To solve your issue, just do this

function openemail(theEmailAddressControl)
{
var email = document.getElementbyID(theEmailAddressControl).va lue;
window.alert(email);
}

Then

string script = "<script language='javascript'>" _
"openemail(" & txtEmailAddress.ClientID & ");" _
"</script>";
Page.RegisterClientScriptBlock("email", script);

Regards
--
Serge Driesen
Dec 12 '06 #2

P: n/a
you are calling the function before the text control is parsed by the
browser. try using RegisterStartupScript("openemail()")

-- bruce (sqlwork.com)

ki*************@consultant.com wrote:
I have a piece of code that calls the clientside it works ok when no
values are passed ie window.alert ('this is a test'). But I have a
value from a textbox example:
function openemail()
{
var email = document.getElementbyID("txtEmailAddress").value;
window.alert(email);
}
when I call this function
string script = "<script language='javascript'>openemail();</script>";
Page.RegisterClientScriptBlock("email", script);
Its gives me an error saying missing object.
Any help will be greatly appreciated
Dec 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.