473,407 Members | 2,546 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,407 software developers and data experts.

Javascript and controls with runat=server?

Hello everyone,

I am have couple of bad concepts and would like to clear things up. As
I understand ASP.NET server controls contain runat=server tag and they
only run on the server. But I've just seen an example where javascript
can access server side controls. Now javascript is about all things
CLIENT, so how can I access server controls from my javascript, here is
one such example
<%@ Page Language="C#" AutoEventWireup="tue" CodeFile="Default.aspx.cs"
Inherits="__Default" %>
<html>
<head>
<script language="javascript" type="text/javascript">

function access()
{
document.getElementById("hidden1").value="hello"
document.getElementById("form1).submit();
}
</script>
</head>
<body>
<form id="form1" action="default.aspx" runat="server" method="post">
<asp:HiddenField Value="He" runtat="server" ID="hidden" />

</form>
</body>
</html>
--------------
Now I am confused how can I access "form and hiddenfield" in my
javascript function. I am accessing server side controls in my
javacript code? How is that possible and more importantly HOW IS THAT
HAPPENING ( What makes it possible to access server side variables from
client side code)?
Please pardon my ignorance. I know this sounds like a basic question
but I need to clear up my concepts. Any help will highly be
apprecaited.
Regards,
Erland

Oct 13 '06 #1
4 13338
most serverside control render some html. if you know what this html looks
like, you can access from javascript, which can access any html on the page.
the server control will usually renders some html element with the id of
ClientId. so try:

function access()
{
document.getElementById("<%=hidden1.ClientID%>").v alue="hello"
document.getElementById("<%=form1.ClientID%>").sub mit();
}

-- bruce (sqlwork.com)
"Erland" <Er************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello everyone,

I am have couple of bad concepts and would like to clear things up. As
I understand ASP.NET server controls contain runat=server tag and they
only run on the server. But I've just seen an example where javascript
can access server side controls. Now javascript is about all things
CLIENT, so how can I access server controls from my javascript, here is
one such example
<%@ Page Language="C#" AutoEventWireup="tue" CodeFile="Default.aspx.cs"
Inherits="__Default" %>
<html>
<head>
<script language="javascript" type="text/javascript">

function access()
{
document.getElementById("hidden1").value="hello"
document.getElementById("form1).submit();
}
</script>
</head>
<body>
<form id="form1" action="default.aspx" runat="server" method="post">
<asp:HiddenField Value="He" runtat="server" ID="hidden" />

</form>
</body>
</html>
--------------
Now I am confused how can I access "form and hiddenfield" in my
javascript function. I am accessing server side controls in my
javacript code? How is that possible and more importantly HOW IS THAT
HAPPENING ( What makes it possible to access server side variables from
client side code)?
Please pardon my ignorance. I know this sounds like a basic question
but I need to clear up my concepts. Any help will highly be
apprecaited.
Regards,
Erland

Oct 13 '06 #2
Bruce,

Thank you for your reply. I understand your explanation partially, I
mean from what you wrote I came to know about another way of aceessing
server side controls from java script ;)

I will appreciate if someone else can explain my question, I will
appreciate that.

--Erland
bruce barker (sqlwork.com) wrote:
most serverside control render some html. if you know what this html looks
like, you can access from javascript, which can access any html on the page.
the server control will usually renders some html element with the id of
ClientId. so try:

function access()
{
document.getElementById("<%=hidden1.ClientID%>").v alue="hello"
document.getElementById("<%=form1.ClientID%>").sub mit();
}

-- bruce (sqlwork.com)
"Erland" <Er************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello everyone,

I am have couple of bad concepts and would like to clear things up. As
I understand ASP.NET server controls contain runat=server tag and they
only run on the server. But I've just seen an example where javascript
can access server side controls. Now javascript is about all things
CLIENT, so how can I access server controls from my javascript, here is
one such example
<%@ Page Language="C#" AutoEventWireup="tue" CodeFile="Default.aspx.cs"
Inherits="__Default" %>
<html>
<head>
<script language="javascript" type="text/javascript">

function access()
{
document.getElementById("hidden1").value="hello"
document.getElementById("form1).submit();
}
</script>
</head>
<body>
<form id="form1" action="default.aspx" runat="server" method="post">
<asp:HiddenField Value="He" runtat="server" ID="hidden" />

</form>
</body>
</html>
--------------
Now I am confused how can I access "form and hiddenfield" in my
javascript function. I am accessing server side controls in my
javacript code? How is that possible and more importantly HOW IS THAT
HAPPENING ( What makes it possible to access server side variables from
client side code)?
Please pardon my ignorance. I know this sounds like a basic question
but I need to clear up my concepts. Any help will highly be
apprecaited.
Regards,
Erland
Oct 14 '06 #3
Hi, since the server controls are rendered to the browsers as ordinary HTML
elements, of course you can access the server control by locating the ID of
the element in the JavaScript. However, there are no access to properties of
ASP.NET server controls in JS. Any changes made upon the controls using JS
may not be saved to its ViewState too.
Regards,
Alvin Chooi
http://alvinzc.blogspot.com
Oct 14 '06 #4
Waquas,

Brice is right and you need to understand one general principle - whatever
happens on the server side the end result is html code that is sent to the
client browser. Simple example:
place textbox control on the page, run the project, view source of the page
( internet explorer go to view->source) what do you see, do you understand
now?
TextBox web server control rendered html similar to this:
<input name="textBox1" type="text" id="textBox1"/>
Any scripting language (such as javascript) is strictly client side thing -
it's part of the DOM (document object model) and allows you to interact with
generated html document (i.e. change the color of the text, navigate to
different page, display message box, get some data from the server via AJAX,
open popup window, etc.) Please read an introduction to asp.net (for
instance: http://www.w3schools.com/aspnet/default.asp) to understand the
basic idea behind asp.net and everything becomes clear.
--
Milosz Skalecki
MCP, MCAD
"wa**********@gmail.com" wrote:
Bruce,

Thank you for your reply. I understand your explanation partially, I
mean from what you wrote I came to know about another way of aceessing
server side controls from java script ;)

I will appreciate if someone else can explain my question, I will
appreciate that.

--Erland
bruce barker (sqlwork.com) wrote:
most serverside control render some html. if you know what this html looks
like, you can access from javascript, which can access any html on the page.
the server control will usually renders some html element with the id of
ClientId. so try:

function access()
{
document.getElementById("<%=hidden1.ClientID%>").v alue="hello"
document.getElementById("<%=form1.ClientID%>").sub mit();
}

-- bruce (sqlwork.com)
"Erland" <Er************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello everyone,
>
I am have couple of bad concepts and would like to clear things up. As
I understand ASP.NET server controls contain runat=server tag and they
only run on the server. But I've just seen an example where javascript
can access server side controls. Now javascript is about all things
CLIENT, so how can I access server controls from my javascript, here is
one such example
<%@ Page Language="C#" AutoEventWireup="tue" CodeFile="Default.aspx.cs"
Inherits="__Default" %>
<html>
<head>
<script language="javascript" type="text/javascript">
>
function access()
{
document.getElementById("hidden1").value="hello"
document.getElementById("form1).submit();
}
</script>
</head>
<body>
<form id="form1" action="default.aspx" runat="server" method="post">
<asp:HiddenField Value="He" runtat="server" ID="hidden" />
>
</form>
</body>
</html>
--------------
Now I am confused how can I access "form and hiddenfield" in my
javascript function. I am accessing server side controls in my
javacript code? How is that possible and more importantly HOW IS THAT
HAPPENING ( What makes it possible to access server side variables from
client side code)?
Please pardon my ignorance. I know this sounds like a basic question
but I need to clear up my concepts. Any help will highly be
apprecaited.
Regards,
Erland
>

Oct 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gary Bagen | last post by:
Hello, I am working on a page transition scheme and was wondering what the quickest way is to find out which ASP.NET controls need to be inside a form with runat=server. I've determined that...
2
by: ola | last post by:
Please Help. I get this error in one of my files Control 'AdminTabControl1_lnk0' of type 'LinkButton' must be placed inside a form tag with runat=server.
3
by: testemail | last post by:
Hello How do I perform a variable replacement in ASP.NET when I am using the runat=server clause to generate a table - it was simple in ASP With ASP : ---------- <HTML> .... <BODY>
3
by: Tina | last post by:
I have been running a javascript function called from <body onload="setcursor" .... But recently I had to add id="mybody" and runat="server to that body tag for other reasons. Now it won't run...
7
by: Alex Maghen | last post by:
I have some client-side JavaScript that I want to run whenever a pulldown <SELECT> is changes on th client. I'm trying to do this as follows... <select id="MyPulldown"...
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
0
by: jdbss | last post by:
How do you access the DOM or HTML controls which are not "runat=server" for a page from server side code? For example, a I want to access each row of a table from the server as well as from the...
6
by: Daniel Jeffrey | last post by:
Hello, I am using an ObjectDataSource with a Custom DataObject etc. Everything is working fine, except when I use a Bound control in a Table Row that is runat="server" As you can see below...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.