I have a component in my application that show in my aspx page a x nurmbers of imagens get from my datasource of a repeater. I want to create a button and make this button print this images. I'd tried window.print() in my aspx, but it's only print the HTML information.
as far as i know,
u can't print directly to the printer.
u need to show the separate window with only img surrounded with div tag.
here is the eample:
<%# Page Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="PrintImage.aspx.cs" Inherits="PrintImage" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<script language="javascript" type="text/javascript">
function PrintImage()
{
printWindow = window.open ("", "mywindow", "location=1,status=1,scrollbars=1,width=600,height=600");
printWindow.document.write("<div style='width:100%;'>");
printWindow.document.write("<img id='img' src='" + document.getElementById('ctl00_MainContent_ImgMyPhoto').src + "'/>");
printWindow.document.write("</div>");
printWindow.document.close();
printWindow.print();
}
</script>
<div>
<asp:Image ID="ImgMyPhoto" runat="server" Width="100px" Height="90px" />
<br />
<input type="button" id="btnPrint" value="Print Image" onclick="PrintImage()" />
</div>
</asp:Content>
ref: this coding is get from Thirumalai_pm
Hope it works!
Related
I have a Master page which is inherited in a aspx page named Employee. Below is the relevant code of the aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Employee.aspx.cs" Inherits="ICA_Nagerbajar.Employee" MasterPageFile="~/Master.Master" %>
<%# Register TagPrefix="e" TagName="Entry" Src="~/EmployeeView/EmployeeEntry.ascx" %>
<%# Register TagPrefix="v" TagName="ViewEdit" Src="~/EmployeeView/EmployeeViewEdit.ascx" %>
<asp:Content ID="ContentBody" ContentPlaceHolderID="MasterBodyPlaceHolder" runat="server">
<div class="tabbable">
<ul class="tabs">
<li>Entry</li>
<li>View/Edit</li>
</ul>
<div class="tabcontent">
<asp:HiddenField ID="TabData" runat="server" />
<div id="tab1" class="tab" style="display:inline-block">
<e:Entry ID="EmpEntry" runat="server" />
</div>
<div id="tab2" class="tab" style="display:inline-block">
<v:ViewEdit ID="EmpViewEdit" runat="server" />
</div>
</div>
</div>
</asp:Content>
Now in one of the ascx page (EmployeeEntry.ascx) Button is working fine. But in the other one(EmployeeViewEdit.ascx) it is not working. Below is the relevant code of EmployeeViewEdit.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="EmployeeViewEdit.ascx.cs" Inherits="ICA_Nagerbajar.EmployeeView.EmployeeViewEdit" %>
<div class="boxed">
<input id="TextBoxUserNameSearch" runat="server" class="textstyle" placeholder="Name" type="text"/>
<asp:Button ID="ButtonSearch" runat="server" Text="Search" class="btnsubmitstyle" OnClick="ButtonSearch_Click"/>
</div>
Server Side Code
#region Search Button Click
protected void ButtonSearch_Click(object sender, EventArgs e)
{
string userName = TextBoxUserNameSearch.Value.Trim();
GetEmployee(userName + "%");
}
#endregion
Few Observations i made
If i replace Button with Link Button its working fine
No Button is working in this ascx though its working in the other ascx
If i comment out the first call to ascx in the parent page then the button is working ie, <e:Entry ID="EmpEntry" runat="server" />
As suggested by #JBKing setting UseSubmitBehaviour property of the Button to "false" solved my problem
<asp:Button ID="ButtonSearch" runat="server" Text="Search" CssClass="btnsubmitstyle" OnClick="ButtonSearch_Click" UseSubmitBehaviour="false"/>
I have created a two usercontrols in asp.net and one webform . Now i want these two usercontrols to show in form in webform but it say that there must be one head with runat="server"
this is webform where i am using UserControl!
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Light.master" CodeBehind="AdministrationPage.aspx.cs" Inherits="DXApplication5.AdministrationPage" %>
<%# Register src="~/AdminPage/AssignmentTab.ascx" tagname="AssignmentUC" tagprefix="uc1" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<table border="0">
<tr>
<td>
<div class="accountHeader">
<uc1:AssignmentUC ID="CalendarUserControl1" runat="server" />
</div>
</td>
</tr>
</table>
</asp:Content>
This is UserControl below:
<%# Control Language="C#" ClassName="AssignmentUC" AutoEventWireup="true" CodeBehind="AssignmentTab.ascx.cs" Inherits="DXApplication5.AdminPage.AssignmentTab" %>
I would add a single form to your masterpage, this may be the cause of your error.
I would also remove all other form server controls from your user controls and pages.
Try these steps:
Go to Light.master master page file and make sure that this is in there somewhere <form id="form1" runat="server"> and a closing tag, the id may be different.
Go to the following files AssignmentTab.ascx and AdministrationPage.aspx and remove any <form id="form1" runat="server"> and closing tags </form>
Check user control code if it contains a head element. Also check all dependencies to see if there are head elements present in them.
I think you have use <form id="formID" runat="server"> in both of your page and user Control .
Just remove runat="server" from your user Control Form tag .
Make sure you have in your user control cs file:
public partial class WebUserControl1 : System.Web.UI.UserControl
In ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebUserControl1" %>
In aspx parent:
<%# Register Src="WebUserControl1.ascx" TagPrefix="uc" TagName="WebUserControl1 " %>
<uc:WebUserControl1 runat="server" ID="mycontrol" />
I have an asp:textbox
<asp:textbox ID="NewName" runat="server" />
and when a user clicks the "Cancel" button, I want to erase whatever is in that text box by making the value just be "". If it were a an input field of type text, I could just do this in javascript:
document.getElementById('NewName').value= "";
But I can't just do this because it is an asp:textbox.
When your asp:textbox is rendered to the UI, then yes, it is just an input field of type text. The only part that may be an issue is the ID, but that can be set using ClientIDMode:
<asp:textbox ID="NewName" runat="server" ClientIDMode="Static" />
renders to:
<input type="text" id="NewName" />
and thus the JavaScript you use should work perfectly.
<asp:TextBox> renders to an <input type="text"> which you can use as you would, the only complication is the id="" attribute is rewritten, but you can do this:
document.getElementById("<%= NewName.ClientID %>").value = "";
Assuming that this script is in the same page as the textbox. If this is in a referenced <script src=""> then you'll need to use a global script variable of the element's ID.
Try setting the textbox's ClientIDMode to Static
That way the javascript should be able to find them with the same ID as in ASPX.
Here a whole test page
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function ClearTB1() {
document.getElementById("TextBox1").value="";
}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p>
<asp:TextBox ID="TextBox1" runat="server" Text="test" ClientIDMode="Static"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server" Text="test" ClientIDMode="Static"></asp:TextBox><br>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ClearTB1()"
CausesValidation="False" UseSubmitBehavior="False" /><br />
</p>
</asp:Content>
I had the same problem. I solved it once I remembered there is a mangling going on with asp.net on the Ids.
within my aspx, i had:
<input type="text" id="sessSubs"/>
further down, within a gridview (hence the use of "class" instead of "id"), i had a column which had an asp:TextBox:
<asp:TextBox runat="server" class="paid" />
once i recalled the id mangling issue, it was just a case of changing the way i referenced the textbox:
<script type="text/javascript">
$(document).ready(function() {
function updateSubs()
{
var sub = parseFloat($('[id$=sessSubs]').val());
$('.paid').val(sub);
}
$(document).on('change, keyup', '[id$=sessSubs]', updateSubs);
});
</script>
i have a div tag within a content tag as i am using a masterpage which has the forms and body tags.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<div id="xxx" style="overflow:scroll; height:450px;">
<asp:GridView ID="GridView1" runat="server" ...>
</asp:GridView>
</div>
</Content>
I wish to maintain the scroll position of the div when any postback happens.
There are jscripts when i search for it but i dont know
how do i apply them with the masterpage.
please help if there is an easier way. or how to use javascript with the above code.
Any help is appreciated.. thanks
You can use AJAX to remove postbacks which will keep your position. More specifically you can take a look at the UpdatePanel control.
Update:
A non-AJAX solution would be to add the following attribute in your page tag.
<%# Page MaintainScrollPositionOnPostback="true" %>
Try this it worked for me.
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<div id="divScroll" style="overflow:auto; height:450px;">
<asp:GridView ID="GridView1" runat="server" ...>
</asp:GridView>
</div>
</Content>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
</script>
</asp:UpdatePanel>
javascript file add the following code:
var scrollTop;
function BeginRequestHandler(sender, args)
{
var m = document.getElementById('divScroll');
scrollTop = m.scrollTop;
}
function EndRequestHandler(sender, args) {
var m = document.getElementById('divGrid');
m.scrollTop = scrollTop;
}
I have the following user-control:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="FadingMessage.ascx.cs" Inherits="includes_FadingMessage" %>
<asp:PlaceHolder Visible="false" runat="server" ID="plhMain">
<span id="<%= this.ClientID+"_panel" %>" style="background-color:yellow; padding:10px;">
<b><%= Message %></b>
</span>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
alert("never gets here??");
jQuery('#<%= this.ClientID+"_panel" %>').fadeOut(1000);
});
</script>
</asp:PlaceHolder>
Which is used in an asp:UpdatePanel. My problem is that $(document).ready is never fired?
How can I detect when a partial rendering has finished?
Put a method in your head tags and then in your placeholder call it. The problem here is that your PlaceHolder Visible="false" so it's never rendered. If you show it dynamically via ajax the script won't run. You'd have to rebind it when you dynamically show the placeholder. I would suggest not using document(ready) ...