[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript sent asp.net label value

Posted on 2014-08-21
3
Medium Priority
?
196 Views
Last Modified: 2014-09-03
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
0
Comment
Question by:R8VI
  • 2
3 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 40277711
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
 

Author Comment

by:R8VI
ID: 40278475
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
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 1500 total points
ID: 40279897
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question