Javascript sent asp.net label value

H,

I have the code below which sends my grid into another popup window, which is fine, but before that I want to add some more values from a label called lbldate how do i do that

            StringBuilder sb = new StringBuilder();


            sb.Append("<script type = 'text/javascript'>");


            sb.Append("window.onload = new function(){");


            sb.Append("var printWin = window.open('', '', 'left=0");


            sb.Append(",top=0,width=1000,height=600,status=0');");


            sb.Append("printWin.document.write(\"");


            sb.Append(gridHTML);


            sb.Append("\");");


            sb.Append("printWin.document.close();");


            sb.Append("printWin.focus();");


            sb.Append("printWin.print();");


            sb.Append("printWin.close();};");


            sb.Append("</script>");


            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

Open in new window


Please help

Thanks

R8VI
R8VIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
The JS change looks like:
document.getElementById('<%=lbldate.ClientID %>').innerHTML = 'Your new label text goes here';

Open in new window

C# to add your JS injection. It assumes the label exists in the page.
sb.Append("document.getElementById('" + lbldate.ClientID +"').innerHTML = 'Your new label text goes here'");

Open in new window

0
R8VIAuthor Commented:
Hi,

To test your suggestion I put in test date but then the pop up doesn't appear please help


 StringWriter sw = new StringWriter();


            HtmlTextWriter hw = new HtmlTextWriter(sw);


            grdWeeklySalesReport.RenderControl(hw);


            string gridHTML = sw.ToString().Replace("\"", "'")


                .Replace(System.Environment.NewLine, "");


            StringBuilder sb = new StringBuilder();


            sb.Append("<script type = 'text/javascript'>");


            sb.Append("window.onload = new function(){");


            sb.Append("var printWin = window.open('', '', 'left=0");


            sb.Append(",top=0,width=1000,height=600,status=0');");


           

            sb.Append("printWin.document.write(\"");

           

            sb.Append(gridHTML);


            sb.Append("\");");

//Test date
            sb.Append("Test Date");


            sb.Append("printWin.document.close();");


            sb.Append("printWin.focus();");


            sb.Append("printWin.print();");


            sb.Append("printWin.close();};");

  
            sb.Append("</script>");

         

            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

Open in new window

0
Miguel OzSoftware EngineerCommented:
This is a complete separate issue from original question, replace line 22 with:
  sb.Append("window.onload = function(){"); //delete new

check onload for more details.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.