how to pass session value to external js file
i got two pages upl.aspx and datalist.aspx
i have got iframe in upl.aspx page which loads datalist.aspx
now i am creating a session on radiobutton click whiich is inside datalist i want to pass this session value to external js file so that now i have a function Hidee() in uploo.aspx page which can show its value
HOW TO DO THIS??
here is my code for up1.aspx
<a onclick="Hidee();" style="cursor: pointer">close</a></div>
<iframe id="frame1" frameborder="0" name="frame1" src="datalist.aspx">&开发者_运维百科lt;/iframe>
this is from datalist.aspx in which i have my datalist
<td align="center" >
<asp:RadioButton ID="rdb" runat="server" CssClass="radio" AutoPostBack="True" OnCheckedChanged="rdb_click" />
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("FileName")%>' />
</td>
</tr>
here is codebehind datalist.cs
public void rdb_click(object sender, EventArgs e)
{
string value = "";
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rdb1;
rdb1 = (RadioButton)DataList1.Items[i].FindControl("rdb");
if (rdb1 != null)
{
if (rdb1.Checked)
{
HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
value = hf.Value.ToString();
}
}
}
Session["Background1"] = value;
Label2.Text = value;
}
and in my external javascript i have function Hidee();
function Hidee()
{
var div2 = document.getElementById( "divframe1" );
div2.style.display = "none";
var div3 = document.getElementById( "aa" );
div3.style.display = "block";
var session ='<%= Session["Background1"] %>';
alert("you have selected" + session);
}
If upl.aspx
and datalist.aspx
are part of two different ASP.NET applications (hosted on different application pools in IIS), it won't be possible to share session between them. A possible workaround would be to pass values as url parameters.
UPDATE:
You cannot use server side expressions in external javascript files. You could declare a global variable in your aspx page that will hold the value which will be used in your javascript file:
In the aspx page:
<script type="text/javascript">
var background = '<%= Session["Background1"] %>';
</script>
and then you could use background
variable in the Hidee
function inside your javascript file.
精彩评论