Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 03, 2012 03:20 PM by roopeshreddy
Member
131 Points
124 Posts
Aug 03, 2012 06:38 AM|LINK
hello every one i want to assign a javascript variable to aspx variable the code for my problem i am giving below....
<script type="text/javascript"> var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); alert(sPage); </script> <% var lastModDate = System.IO.File.GetLastWriteTime(sPage); %>
i am not able to do the above task can any1 help me out....
Any help would be appreciated...:)
All-Star
34535 Points
5554 Posts
Aug 03, 2012 06:42 AM|LINK
try this
<script type="text/javascript"> var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); alert(sPage); var lastModDate = <% System.IO.File.GetLastWriteTime(sPage) %>; </script>
hope this helps...
Contributor
4483 Points
868 Posts
Aug 03, 2012 08:06 AM|LINK
Hi Friend,
If you want to do this, So first javascript must fire on load, then variable will get value.
refer link.
http://forums.asp.net/t/1043216.aspx/1
Aug 03, 2012 11:16 AM|LINK
Thanks for giving me your precious time. I need to print that variable how to do it can help a bit more.
Aug 03, 2012 11:32 AM|LINK
direct_tarun Thanks for giving me your precious time. I need to print that variable how to do it can help a bit more.
what u mean by print the variable?
do u want to display value of the variable? u can use alert() for that... like this
var lastModDate = <% System.IO.File.GetLastWriteTime(sPage) %>; alert(lastModDate);
43056 Points
7040 Posts
MVP
Aug 03, 2012 12:37 PM|LINK
Hello,
Use hidden field to pass the value to the code behind
In your aspx,
<asp:HiddenField ID="HiddenField1" runat="server" />
In your JavaScript
document.getElementById('<%=HiddenField1.ClientID %>').value = "Value in javascript";
In code behind
string valueInCodeBehind = HiddenField1.Value;
Please 'Mark as Answer' if this post helps you.
29935 Points
5821 Posts
Aug 03, 2012 02:23 PM|LINK
JavaScript runs on the browser, Serverside code runs on the server. The JavaScript code can not give the server code information!
Eric
20155 Points
3328 Posts
Aug 03, 2012 03:20 PM|LINK
Hi,
If you wanna print, then assign the content to any element and you can print!
<span id="fileTime"></span> <script type="text/javascript"> document.getElementById("fileTime").innerHTML = lastModDate; </script>
Hope it helps u...
direct_tarun
Member
131 Points
124 Posts
problem in assigning a javascript variable to aspx variable
Aug 03, 2012 06:38 AM|LINK
hello every one i want to assign a javascript variable to aspx variable the code for my problem i am giving below....
<script type="text/javascript"> var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); alert(sPage); </script> <% var lastModDate = System.IO.File.GetLastWriteTime(sPage); %>i am not able to do the above task can any1 help me out....
Any help would be appreciated...:)
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 06:42 AM|LINK
try this
<script type="text/javascript"> var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); alert(sPage); var lastModDate = <% System.IO.File.GetLastWriteTime(sPage) %>; </script>hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Ajay2707
Contributor
4483 Points
868 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 08:06 AM|LINK
Hi Friend,
If you want to do this, So first javascript must fire on load, then variable will get value.
refer link.
http://forums.asp.net/t/1043216.aspx/1
direct_tarun
Member
131 Points
124 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 11:16 AM|LINK
Thanks for giving me your precious time. I need to print that variable how to do it can help a bit more.
kedarrkulkar...
All-Star
34535 Points
5554 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 11:32 AM|LINK
what u mean by print the variable?
do u want to display value of the variable? u can use alert() for that... like this
var lastModDate = <% System.IO.File.GetLastWriteTime(sPage) %>;
alert(lastModDate);
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Ruchira
All-Star
43056 Points
7040 Posts
MVP
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 12:37 PM|LINK
Hello,
Use hidden field to pass the value to the code behind
In your aspx,
In your JavaScript
document.getElementById('<%=HiddenField1.ClientID %>').value = "Value in javascript";In code behind
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.A1ien51
All-Star
29935 Points
5821 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 02:23 PM|LINK
JavaScript runs on the browser, Serverside code runs on the server. The JavaScript code can not give the server code information!
Eric
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: problem in assigning a javascript variable to aspx variable
Aug 03, 2012 03:20 PM|LINK
Hi,
If you wanna print, then assign the content to any element and you can print!
<span id="fileTime"></span> <script type="text/javascript"> document.getElementById("fileTime").innerHTML = lastModDate; </script>Hope it helps u...
Roopesh Reddy C
Roopesh's Space