473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

calling javascript function from asp.net

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
2 3748
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
18
by: Simula | last post by:
I am developing an HTML javascript application and I want to preserve state in a way that can be book-marked. I chose HTML anchors as a means of preserving state. When the application changes...
4
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB...
13
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is...
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
6
by: Ajit Goel | last post by:
Hi; We have a Javascript function which I have been tasked to move to a CSharp class. This javascript function uses Regular expression extensively. This function has a string input parameter and...
2
by: moni | last post by:
Hi, I wanted to call a javascript function function showAddress(address) { ..... } from the aspx.cs file from the Gridview_RowCommand function
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
15
by: Sampat | last post by:
Hi, I wanted to know the performance of calling a function pointer v/s a normal function call in javascript in a scenario where there are multiple calls in the js to the same function. Please...
9
by: mrcheeky | last post by:
Hi, I'm stuck, but it's almost working! From a html page, my javascript calls a server-side php script. The php reads a value from a server-side .txt file and passes it back as a javascript...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.