Hi
I am new for web development. I wasted fewdays but I am not able to figureout following problem.
1. I have Javascript variable I want to use in Server side C# is it possible ?
2. If above is not possible if i declare variable in C# and is it possible to update through Javascript ?
As I am new for web development Please give me sample code for example it will be very easy for me to understand. If both way possible please explain me both way.
Thanks in anticipation
Harshad
![]() |
0 |
![]() |
Yes it is possible to get the value of your javascript variable in C#. here's how:
1. In javascript suppose you have a variable called x.
2. Add a hidden server-control to the page:
<input type="hidden" id="hid" name="hid" runat="server" />3. In javascript assign the value of x to hidden control as
document.getElementById("<%= hid.ClientID %>").value = x;
4. On the server side code in C# when you can access the hidden variable value containing value of x as:
string str = hid.value.ToString();
Hope this helps.
AJ
Please don't forget to click “Mark as Answer” on the post that helped you.
![]() |
0 |
![]() |
Thanks a lot Ashish.
I am using Component Art Combobox with runat "Callback". I tried the way you suggested but i am not receiving value from server side. It showing error on the name of hidden variable in C#. If I use Input submit button i am getting value on server side but i don't want to use button event on change selection of combobox i am creating string that string i want to pass along with index change. Means i want to send two information one is value of changed index and other is string which i generated at the time of changed event. Changed selection event woking fine but i want to send string from javascript to c#(server side).
I can send two string combine but on server side there is other event data_request that stop working if i send information of selection changed it working fine. My idea is in data_reqest event i want access the string which is generated in javascript from C#.
Please show me way i stuck.
Once again thanks
Harshad Gandhi
![]() |
0 |
![]() |
Hi test37
Based on my understanding, you are working with the third-party control ComponentArt, right?
If so, I would like to suggest you check their support center:
http://www.componentart.com/support/
Because this is an ASP.NET forum, and community members here may not familiar with that control.
Thanks.
Lance Zhang
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
1. I have Javascript variable I want to use in Server side C# is it possible ?
answer : the bridge b/w the javascript and the serverside are the Html Form Fields which are available to both (client and server), so put your javascript values inside hidden(or not hidden) form fields and use them on the server side by.
2. If above is not possible if i declare variable in C# and is it possible to update through Javascript ?
answer : same as above..
SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
![]() |
0 |
![]() |
test37:
1. I have Javascript variable I want to use in Server side C# is it possible ?For that you can use Server side tags and assign the value from server to javascript variable
Eg
var temp = '<%=str%>';
where str is a server side variable
test37:
2. If above is not possible if i declare variable in C# and is it possible to update through Javascript ?
But Updating a a normal variable can be done only using a postback if you want to update session variable you have an optionto make a asynchronous call and do it
MAK | Mark as Answer if this reply helps you | |
![]() MVP ASP/ASP.Net | ASP.Net Hosting : Host Depot | My Site : ASPSnippets |
![]() |
0 |
![]() |
Hi,
U can use classical
http://www.w3schools.com/ajax/ajax_database.aspor u can use Ajax.net
Hope it helps
Thanks
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
![]() |
0 |
![]() |