set session variable value in JavaScript in ASP.NET page load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waqasahmd
    New Member
    • Nov 2009
    • 13

    set session variable value in JavaScript in ASP.NET page load

    Hi,
    I have this code in my pageload but the problem is i want rm_id which i am gettin from session should be set in the javascript code in place of 261 hard code value at line#5( var rmid = 261;) i use concatination opr but it dose'nt work out.
    Code:
    int rm_id = Convert.ToInt32(Session["rmid"]);
            //var rmid = <%=  Convert.ToInt32(Session['rmid']) %>
            string updateParentScript = @"function updateParentWindow()
                                    {
                                    var rmid = 261;
                                    window.opener.updateValues(rmid); 
                                    alert(rmid);
                                    window.parent.location.reload();
                                    window.close(); 
                                  }";
            this.ClientScript.RegisterStartupScript(this.GetType(), "UpdateParentWindow", updateParentScript, true);
            btn_close.Attributes.Add("onclick", "updateParentWindow()");
  • waqasahmd
    New Member
    • Nov 2009
    • 13

    #2
    set session variable value in javscript in ASP.NET page load

    Hi,
    i want to have rm_id value set to rmid in updateparentScr ipt in place of 261 hardcode i use concatinaion but it dose'nt work and

    Code:
    btn_close.Attributes.Add("onclick", "updateParentWindow()
    doesnot get executed

    Code:
    int rm_id = Convert.ToInt32(Session["rmid"]);
            //var rmid = <%=  Convert.ToInt32(Session['rmid']) %>
            string updateParentScript = @"function updateParentWindow()
                                    {
                                    var rmid = 261;
                                    window.opener.updateValues(rmid); 
                                    alert(rmid);
                                    window.parent.location.reload();
                                    window.close(); 
                                  }";
            this.ClientScript.RegisterStartupScript(this.GetType(), "UpdateParentWindow", updateParentScript, true);
            btn_close.Attributes.Add("onclick", "updateParentWindow()");

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Please don't double-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Did you try:
        Code:
        StringBuilder updateParentScript = New StringBuilder();
        
        updateParentScript.Append("function updateParentWindow() \n");
        updateParentScript.Append("{ \n");
        updateParentScript.Append("  var rmid =");
        updateParentScript.Append(Convert.ToInt32(Session['rmid']).ToString);
        updateParentScript.Append("\n");
        updateParentScript.Append("  window.opener.updateValues(rmid);  \n");
        updateParentScript.Append("  alert(rmid); \n");
        updateParentScript.Append("  window.parent.location.reload(); \n");
        updateParentScript.Append("  window.close();  \n");
        updateParentScript.Append("}"; \n");
        
        this.ClientScript.RegisterStartupScript(this.GetType(), "UpdateParentWindow", updateParentScript.ToString(), true);
        btn_close.Attributes.Add("onclick", "updateParentWindow()");
        To use a StringBuilder you have to use the System.Text namespace.


        -Frinny

        Comment

        Working...