Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, November 19, 2013 9:08 AM
hi all i have a putton that insert the data on sql and genrate uniq ID in a pop out alret i wanted it to print a specfic DIV and Panel ...... here is my ending code of the button :
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Your Request Id is: " + UID + "');");
Response.Write("document.location.href='New Request.aspx';");
Response.Write("</script>");
All replies (10)
Tuesday, November 19, 2013 10:05 AM ✅Answered
You can put the dynamically generated ID in your divID.innerHTML as I mentioned above.
And if you would like to print a specific div on your page, That can be done by using javascript window.print() method.
References:
http://stackoverflow.com/questions/7791158/print-div-contents-in-javascript
http://www.mindfiresolutions.com/Printing-content-of-a-particular-div-1014.php
http://www.codeproject.com/Tips/503415/Print-Div-Content-Using-JavaScript
However, if you want to call javascript from your code behind, then, you would need to use ScriptManager.RegisterStartupScript() method. There are other methods as well in ScriptManager.
Tuesday, November 19, 2013 12:54 PM ✅Answered
ok i got it working now if i stoped the alart ..... and also a print screen come up can i by pass this to print right away !
in the .asp code
<script language="javascript" type="text/javascript">
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;
//Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
</script>
in the Cs
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "printDiv", "printDiv('Div1');", true);
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Your Request Id is: " + UID + "');");
Response.Write("document.location.href='New Request.aspx';");
Response.Write("</script>");
Wednesday, November 20, 2013 4:47 AM ✅Answered
Good to see that the articles supplied have helped you - as I could see you have used printDiv function and ScriptManager functions from the supplied pointers.
Please mark the threads which helped you as answer, so that it will be useful for the others while searching for the same issue and they can then go through the related articles to understand the concept fully..
Tuesday, November 19, 2013 9:44 AM
You can create the div dynamically by using HtmlGenericControl.
Reference: http://msdn.microsoft.com/en-us/library/5f8y80ez%28VS.80%29.aspx
void Page_Load(Object sender, EventArgs e)
{
// Create a new HtmlGenericControl.
HtmlGenericControl NewControl = new HtmlGenericControl("div");
// Set the properties of the new HtmlGenericControl control.
NewControl.ID = "NewControl";
NewControl.InnerHtml = "This is a dynamically created HTML server control.";
// Add the new HtmlGenericControl to the Controls collection of the
// PlaceHolder control.
ControlContainer.Controls.Add(NewControl);
// Here ControlContainer is the ID of the asp:PlaceHolder defined in the aspx page. Just for example.
}
<asp:PlaceHolder ID="ControlContainer" runat="server"/>
Tuesday, November 19, 2013 9:56 AM
and where is the print code !!
can i just do a print to some valuse i entered !!!! that will be ok for me as will
Tuesday, November 19, 2013 10:58 AM
Thank you so much for you support i have run through this Java script the thing is i dont want to have another button and the button i have alrady do some other function and end up with the above code so is there a way i can call that java script befor the alrt !!!
and as i mentioned i dont care if its specfic div any more i can be happy with some value i chose that that uses entered on the text box
Tuesday, November 19, 2013 11:42 AM
Yes, you can write your printdiv function in your .aspx code.
And you can call the printdiv function exactly in the same line, like how you are calling alert function.
Hope this clarifies.
Wednesday, November 20, 2013 12:11 PM
Thank you for you support :)
Wednesday, November 20, 2013 12:11 PM
thank you
Thursday, November 21, 2013 9:28 AM
for some reson i am geting the
Line: 4621
Error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
Parameter name: element
after printing any one know why ?