How to set value of a server control on Clint side using javascript.

I have defined toDayHidden filed in .aspx as     .

<form>
    ......
    <asp:Label ID="toDayHidden" runat="server" Text="";></asp:Label>
    ....
</form>

On the client side I would like to set the value of this label to a date value so that I can use the client date on the server. I tried the following but it does not set the value of this control but it does not set the value of the control.

document.getElementById('<%= toDayHidden.ID %>').innerText = new Date();

and also

document.getElementById('<%= toDayHidden.ID %>').value = new Date();

What can I do to set the value of the control?

 

 


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
8/20/2008 3:49:30 PM
asp.net.client-side 24353 articles. 1 followers. Follow

7 Replies
805 Views

Similar Articles

[PageSpeed] 52

Any help on this?


Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
8/20/2008 5:22:38 PM

SKVSKV:

I have defined toDayHidden filed in .aspx as     .

<form>
    ......
    <asp:Label ID="toDayHidden" runat="server" Text="";></asp:Label>
    ....
</form>

On the client side I would like to set the value of this label to a date value so that I can use the client date on the server. I tried the following but it does not set the value of this control but it does not set the value of the control.

document.getElementById('<%= toDayHidden.ID %>').innerText = new Date();

and also

document.getElementById('<%= toDayHidden.ID %>').value = new Date();

What can I do to set the value of the control?

 

 

Try this...

document.getElementById('<%= toDayHidden.ClientID %>').innerHtml = new Date(); 

Server control ID gets renamed when rendered. "ClientID" will get you that renamed ID.

0
briankim1122
8/20/2008 9:35:32 PM
Thank. The code I have works and sets the value of the variable. It appears that it set the value of the variable after the the server side has been called. However, I somehow need to se the value before the server side code is called to display the form because the form contains the data that is based on a sql query which is baed on a date. I somehow nned to get the client date on the server and pass it to the query before the query is executed on the server. Where should I be setting the client date in the hidden field?
Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
8/20/2008 10:47:33 PM

I now see what you are trying to do...

After page loads and date value is set on the hidden field, you can get the client date value on a postback, but I don't know if that's what you want to do...

I don't think there is a way to get the client time before page loads since you can only get the client time when page loads and javascript runs.

Maybe you should look into how AJAX can help. You could use async post back to run query after page loads and you have the client date.

0
briankim1122
8/20/2008 11:02:43 PM

A Label changed client-side does not persist changes server-side. Use a hidden element instead:

<input type="hidden" id="hiddenElement" name="hiddenElement" runat="server">

<script type="text/javascript">
<!--
document.getElementById('<%= hiddenElement.ClientID %>').value = 'some new value';
// -->
</script>

Server-side:
Get:
     string newValue = hiddenElement.Value;
Set:
     hiddenElement.Value = "some new value";

NC...

0
NC01
8/21/2008 5:31:21 PM
Thanks, NC.
Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
0
SKVSKV
8/22/2008 5:11:57 AM

No problem. You're not the first that has tried that.

NC...

 

0
NC01
8/22/2008 11:44:48 AM
Reply:

Similar Artilces:

Setting the value of server side variable in javascript and wants to use that server side variable on page load.
Hi, I am trying to set the value of a server side variable in javascript and wants to use that variable on page load.  Here is my sample code. -------------------------- private string testVal = null;  private void registerScript(){ if (!this.Page.ClientScript.IsClientScriptBlockRegistered("RequestHeaderValidation")){ StringBuilder sb = new StringBuilder("" + Environment.NewLine);sb.Append(" var version = '2.0'; " + Environment.NewLine); sb.Append(" var isInstalled = Silverlight.isInstalled(version);" + Environment.NewLine)...

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite 7.1.0.300) Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

How to access dynamically Html controls (client side controls) using C# server side scripts
Folks,I have problem try to to access dynamically Html controls (client side controls) using C# server side scripts. Please give me helps.     The error is as follows Exception Details: System.InvalidCastException: Specified cast is not valid.Source Error: Line 79: { Line 80: Control c = Page.FindControl("ddlTC" + i); Line 81: ((DropDownList)c).DataSource = mdt; Line 82: ((DropDownList)c).DataTextField = "ClassID"; Line 83: ((DropDownList)c).DataValueField = "Course"; My aspx page source codes: ...<...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in asp.net ( required field, range validator and others)..my question is the required field validator is a server side control. So does that mean that it does a post back?..is it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

Client side clock using server side controls
Is it possible to create a client side clock using a server side control (label or textbox) in C# without accessing JavaScript?  If so, how? In principal it is possible, it depends how often you need to reload this clock ... if every second than: 1. It is no sens to do I mean 2. You need than to make setTimeout client script, to refresh page every second With FastPage it seems more real task ... http://fastpage.more.at...

Issue obtaining values in server-side from dropdownlist when updating value using client-side script in master page
HiI got a page in a contentplaceholder of a master page. There is two pulldowns. I populate the first one using server side coding and then use client-side javascript. So far so good. The issue is that upon a postback I try to collect the select value of the second pulldown and there is no data in the pulldown and no selected item. I tried using control.selectedvalue (nothing) or searching the form controls Stringvariable = oForm.FindControl("Control")Thing is I've done this before in 1.1 outside of a master page and it works.Thanks in ad...

How to take value from client side control from server side code?
Hi all, I would like to know that, how to access client side control in server side code? Here is an example.. I am having the textBox in client side like <input type="text" id="textBoxUsername" name="textBoxUsername"/> I need to take the value from this textBox in button click event which is server side code. private void buttonShow(object sender, System.EventArgs e) { //I need to access this textBox here. } How to do that? Thanks R. eswaran. hi you need to make it run at server. <input type="text" id="textBoxUsername"...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

Set the value of a server control on client-side
I have tried many ways for a couple of days, but was not successful. I have a javascript that I register at startup (inside Page_Load method) and an input field running on server-side. I try from the javascript to set the value of the hidden input field like this: document.form1.HiddenField.value = 'true'; Every time I try to retrieve the value on server-side at Page_Load, it is empty even after postback (load the page again - not refresh). I even tried this: document.getElementById('HiddenField').value = 'true'; but still not working. What I am thinking is that maybe...

server side control passing value of self in client side function
I have a server side dropdownlist control.It contains values as:"#00FFFF""#FF00FF""#FFFF00"When the selectedindex is changed by the client I want to assign the value of the dropdownlist to a <div id="example"></div> evelement.pseudo:document.getElementbyId('example').bgcolor=dropdownlist.valueHow can I do this? I think I somehow need to attach a function to my dropdownlist which passes its own value as a parameter to a function...any suggestions?Thanks!please mark answers as 'Answered' and post back solutions when you figure stuff out that isnt in the post already. You ...

validation, is it better to have client side or use server side validator controls
 Hi All. I want to do validation on text boxes etc. Is it better to do client side validation or just use the server side validation controls?   Hi!  If for server side controls you mean RequiredFieldValidator, CompareValidator, RegularExpressionValidator, etc.. i can tell you that they use client and server validation. For instance if you use a RequiredFieldValidator, on the client will be a validation, but on the server this condition will be evaluated again. Probably one of the objetives of this is deal with client with javascript disabled. Of course I ...

Combining a server-side control with a client-side control!
Hi all, I am trying to combine a server-side control with a client-side control. I have created a listbox in both sides, the client-side control's code is: <select size="4" name="lstFruit" id="Select1" ondblclick="lst_dblClick" visible="false"> <option value="Banana">Banana</option> <option value="Apple">Apple</option> <option value="Mango">Mango</option> <option value="Orange">Orange</option> </select> The other one is the server-side control which has this code:   I wanted to add the ondblClick attribute to the se...

What are diff Server-side control and Client-side control ?
What are diff Server-side control and Client-side control ? and diff server -side coding and client -side coding ? please help I have answered the first part of your question in your previous posting. Server-side coding languages are ASP, ASP.NET, PHP, CGI (Perl) and many, many more. They are used to create dynamic web content (based on additional information that is attached to the request) and are often used to extract information from databases. Client-side coding languages are JavaScript, VBScript, EMACScript and are used to create dynamic content that responds to the u...

textbox value set on client side, is not visible on server side or, on the source of the page.
hi, I have a textbox on my webform. the first time I load my page I fill this textbox with  "name" on the server side. once the page is loaded I set the value of the textbox to "thisIsme" with client side code. I even see a different text in the texbox. client side:document.all('txtnameInput').value =  'thisIsme'; server side:Me.txtnaam.Text 'is stil "name" and not "thisIsme" Why is this happening? on the webpage I see the text "thisIsme", but when I look at the source of the webpage I still see the old value in it. it's very odd... I am NOT setting the value back to "name...

Web resources about - How to set value of a server control on Clint side using javascript. - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 12/19/2015 10:02:53 AM