changing value of html control from c# code in asp.net website

S

saurabh

Can anybody tell me how to change the value of an html control from the
c#....
eg i hv one asp.net radio button control and one html hidden
variable...
so on page load in case the radio button is checked i want to set this
hidden variable to 1 else 0...

I am not getting what to write in Page_Load(object sender,
System.EventArgs e) function to change the value of this html
variable...
 
G

Guest

I think it might be easier just to use a server control becuase otherwise for
the most part the server doesnt even know it exists.
Depending on your needs that might be the best solution.

even if you went the route of having the server re-create the html control
 
S

saurabh

as per requirments this might not be possible in my case....Does any
body has idea at any one of the following:
1) To check if a server control radiobutton checked or not , using the
javascript, each time page is loaded....If u know tell me wht all steps
need to be taken.
2) or to change the value of a hidden html variable from inside the c#
code that we write in asp.net website....
-----------------
 
G

Guest

1. getting access to values of serverside controls using javascript is a
subject that was lightly touched on in one of my books called "ASP.Net 2.0
Advanced Application Design" and its labeled as "expert" content. Its also a
very messy and long process from the best I can tell.
If you set a server control autopostback = true then the second the user
checks that checkbox your server side will know its been checked. That said
autopostback makes a round trip to the server which is usually not an issue
but sometimes its perfered the user doesnt see a refresh of the page unless
they have to.
2. I have no idea what you are talking about here. HTML variable?
 
G

Guest

just so i get an idea of your background do you know what viewstate is?

This will help me no repeat information that you already know.
 
S

saurabh

by html variable i mean a hidden html variable or say a textbox....is
thr any way to change the text of a text box from the c# code?? point
it tht textbox is not a server control , so textbox.text="blahblah"
wont work...
 
G

Guest

I have used webserver controls and hidden them on the page for similar
reasons however for a client side control all values are lost on each post to
the server unless you keep the value in a cookie, viewstate, sessionstate etc.

That is why I asked if you know what viewstate is. If you dont, then there
is a bit of a learning curve on how to keep values in the web applications
 
S

saurabh

yeah exactly this is the prblm i am facing....after each trip to server
my html hidden control looses its value....if i am able to store this
value i think my problem will be solved...
no boss i dnt know abt this viewstate and all....i am kindaa new is
asp.net :(
 
G

Guest

fair enough on viewstate that gives me a good idea in the area we are talking
about.

My question at this point would be why do you require a clientside HTML
checkbox instead of a serverside checkbox?

<asp:CheckBox ID="CheckBox1" runat="server" />

above will maitain state of value automatically :)
 
S

saurabh

hey its kindaa difficult to explain u my prob this way...can u gimme ur
messenger contact(if u dnt mind)....will tell u thr...
hey i am working on this html variable in a javascript....if i put
checkbox instead of tht it wont be possible to manipulate tht asp
checkbox frm javascript written in html control
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top