views:

494

answers:

1

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"></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);
}
+1  A: 

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.

Darin Dimitrov
These two pages are part of same website
sumit
It doesn't matter. You lose state from page to page.
monksy
@steven Isn't the whole point of session to keep track of state from page to page?
Justin Johnson
When you say `external` javascript do you mean a separate .js file from your aspx page, because if this is the case you cannot write <%= `Session["Background1"] %>` inside.
Darin Dimitrov
yes it is .js file,,but then what should i write
sumit
Please see my update.
Darin Dimitrov
@Darin"you could use background variable in the Hidee function inside your javascript file" but wheni use background in my external js file it says background undefined.
sumit
Did you declare the variable in the `head` section of the aspx page as shown in my example?
Darin Dimitrov