accessing sever controls in .js file

2 views
Skip to first unread message

Madhu

unread,
Aug 11, 2009, 7:20:55 AM8/11/09
to Bangalore GTUG
Hi..

How can i access the value entered in the textbox in aspx page
from .js file? Also how can i execute that .js file when button is
clicked?

Thanks in advance..

Abhishek Mishra

unread,
Aug 11, 2009, 7:58:00 AM8/11/09
to bangalo...@googlegroups.com
hmm javascript right,

set the onclick attribute of input tag that you use for button to the javascript function you wrote.
and as for accessing values in a textbox, give it an id, and then in js access it like this -
var beep = document.getElementById("foo").value;

where 'foo' is the id of that textbox.

hope that helps.

Madhu Keshwar

unread,
Aug 12, 2009, 12:35:59 AM8/12/09
to bangalo...@googlegroups.com
Hi..

Ya Abhishek i tried in same way you told. Function name in .js file
is getvalue() and the button id is "val". But it is giving error like
below..

Error 1: 'ASP.default_aspx' does not contain a definition for
'getvalue' and no extension method 'getvalue' accepting a first
argument of type 'ASP.default_aspx' could be found (are you missing a
using directive or an assembly reference?)

I given the javascript link in <head > in aspx page. How to over come this?

Abhishek Mishra

unread,
Aug 12, 2009, 1:00:51 PM8/12/09
to bangalo...@googlegroups.com
I'm not so familiar to ASP, but I suspect that the javascript is getting executed before the html is rendered, so maybe it is not able to access the DOM element in question. What about using jQuery, try it, it makes life really easy with simple selectors and good control over events. Maybe putting your javascript under document load event would be of some help.

tc
Abhishek Mishra

Nishanth Anil

unread,
Aug 12, 2009, 1:23:23 PM8/12/09
to bangalo...@googlegroups.com
Use the ClientID property of the control in the aspx page, and then use document.getElementById("ClientId").value.
Replace the ClientId with the value what you provided in the aspx page. Let me know if you still are not clear.


 
On Tue, Aug 11, 2009 at 4:50 PM, Madhu <mpmadhuk...@gmail.com> wrote:
--
Regards
Nishanth Anil
nishan...@gmail.com

Madhu Keshwar

unread,
Aug 13, 2009, 12:28:37 AM8/13/09
to bangalo...@googlegroups.com
Ya Anil i tried that one also but ".value" didn't worked properly.
Will u please explain in detail with an example about how to use that.

Now i tried in other way and it is working..
In my .aspx.cs page i'm storing a value in some label called
"Label1" and in .aspx page inside script i called the function in .js
file like below..

<script type="text/javascript">
dispcal(document.getElementById("<%=Label1.ClientID%>").innerHTML)
</script>

where dispcal() is a function name in .js file. and passing value inside that..

Reply all
Reply to author
Forward
0 new messages