Jump to content

Setting Session Variables From A .ascx File Using Client-side Script


ponki.d.monkey
 Share

Recommended Posts

Hi! I just want to know how to set a session variable from a .ascx file (without a code-behind) using client side script or inline code. The .ascx file was created using dreamweaver, now we're trying to get some values from the .ascx file (using Visual Web Developer) and store those values in a session variable. How do we do it without code-behind? Is it possible? Thanks if anyone can answer this question....

Link to comment
Share on other sites

Hi aspnetguy,The code looks something like this:

<script type="text/javascript">//some javascript</script><table width="250" border="0" cellpadding="0" cellspacing="0">	<tr>		<td valign="top" align="left" class="glossymenu">			<a class="menuitem submenuheader" href="java script:void(0)" onclick="SomeJavaScriptFunc()">Website Development</a>			<a class="menuitem submenuheader" href="java script:void(0)" onclick="SomeJavaScriptFunc()">e-Commerce</a>		 </td>	 </tr></table>

So as you can see it doesn't have a page directive like any usual .ascx or user control file since it was created using dreamweaver. What we want to do is when we click the "Website Development" link, the session variable will be set to "Website Development" else if we click the "e-Commerce" link, it will be set to "e-Commerce." Now the problem is the file doesn't have a code-behind file like any usual .ascx file and we don't want to put a code-behind because it will affect the behavior of the control (since it was created using dreamweaver). We're also aware that we cannot set the session variable through javascript and the only other way we can do it is either by using an inline code or using AJAX. But then again, now that I've thought about it, AJAX still requires a code-behind file. So thinking about, the only option that we have as using inline code. We can just put a page directive then use the script tags. Now, we tried that, but the .ascx file doesn't recognize the script tag. So now, we don't know what other options we have. Any ideas? Thanks for the reply....

Link to comment
Share on other sites

I am afraid to say you cannot do this without a code behind. The server holds the session information in memory and all the client side can do is pass the cookie which is the session key back and forth. So unless you go with cookies or something yourself to determine what you are doing you will not be able to achieve what you want. Another option is the AJAX you spoke of why are you so against code behind?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...