Foo.ClassName = 'classname' not working - javascript

The first six lines work the classname lines do not.
function ShowShippingInfo() {
var QuoteInfo = document.getElementById("QuoteInfo");
var ShippingInfo = document.getElementById("ShippingInfo");
var Comments = document.getElementById("Comments");
QuoteInfo.style.display = "none";
ShippingInfo.style.display = "block";
Comments.style.display = "none";
QuoteInfo.className = 'tab';
ShippingInfo.className = 'tab active';
Comments.className = 'tab';
};
Here is my html
<div onclick="ShowQuoteInfo();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Quote Info</strong></div>
<div onclick="ShowShippingInfo();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Shipping Info</strong></div>
<div onclick="ShowComments();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Comments</strong></div>
The problem I am having it is not changing the classname and I know the class tab and tab active works because it works when I set it manueally
Also setting the backgroundcolor doesn't work either.
I am using Google Chrome
Please help
Thanks
PS: here are the dives it is showing and hiding
<div id="QuoteInfo">
<table class="table_1">
<tr>
<td style="vertical-align: top;" class="auto-style169" rowspan="2"><strong>Customer:</strong></td>
<td class="auto-style165" rowspan="2" style="vertical-align: top">
<asp:DropDownList ID="TCustomer" runat="server" Style="font-weight: bold;" AppendDataBoundItems="True" DataTextField="Name" DataValueField="Name" Height="27px" Width="171px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="LAddress" runat="server" Text="_"></asp:Label>
</td>
<td class="auto-style197"><strong>Quote</strong> <strong>No:</strong></td>
<td class="auto-style197">
<asp:TextBox ID="TQuoteNumber" runat="server" Width="182px" Enabled="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style196"><strong>Date:</strong></td>
<td class="auto-style196">
<asp:TextBox ID="TDate" runat="server" Width="182px" Enabled="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style194"><strong>Contact Person:</strong></td>
<td class="auto-style195">
<asp:TextBox ID="TContactPersonss" list="Contact" runat="server" Width="182px"></asp:TextBox>
</td>
<td class="auto-style195"><strong>Sales</strong> <strong>Person:</strong></td>
<td class="auto-style195">
<asp:TextBox ID="TSalesPerson" runat="server" Width="182px" Enabled="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style169"><strong>Status:</strong></td>
<td class="auto-style165">
<asp:DropDownList ID="TStatus" runat="server" Style="font-weight: bold;" AppendDataBoundItems="True" DataSourceID="SqlDataSource2" DataTextField="ItemName" DataValueField="ItemName" Height="27px" Width="171px">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DRPConnectionString %>" SelectCommand="SELECT [ListName], [ItemName] FROM [Status] WHERE ([ListName] = #ListName)">
<SelectParameters>
<asp:Parameter DefaultValue="QuoteStatus" Name="ListName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td class="auto-style165"><strong>Expires</strong> <strong>in</strong> <strong>(Days):</strong></td>
<td class="auto-style165">
<asp:TextBox ID="TExpiresIn" runat="server" Width="182px" TextMode="Number"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style179"><strong>Estimated Lead Time:</strong></td>
<td class="auto-style180">
<asp:DropDownList ID="TEstimatedLeadTimes" runat="server" Height="26px" Width="223px">
<asp:ListItem Selected="True">None</asp:ListItem>
<asp:ListItem>1 to 2 weeks</asp:ListItem>
<asp:ListItem>2 to 3 weeks</asp:ListItem>
<asp:ListItem>3 to 4 weeks</asp:ListItem>
<asp:ListItem>4 to 5 weeks</asp:ListItem>
<asp:ListItem>5 to 6 weeks</asp:ListItem>
<asp:ListItem>6 to 7 weeks</asp:ListItem>
<asp:ListItem>7 to 8 weeks</asp:ListItem>
<asp:ListItem>8 to 9 weeks</asp:ListItem>
</asp:DropDownList>
</td>
<td class="auto-style180"><strong>PO Number:</strong></td>
<td class="auto-style180">
<asp:TextBox ID="TPurchaseOrder" runat="server" Width="182px"></asp:TextBox>
</td>
</tr>
</table>
</div>
<div id="ShippingInfo" style="display: none;">
<table class="table_1">
<tr>
<td style="vertical-align: top;" class="auto-style189">Name:</td>
<td class="auto-style165" style="vertical-align: top">
<asp:TextBox ID="TextBox16" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
<br />
</td>
<td class="auto-style192">Same as Customer:</td>
<td class="auto-style157">
<asp:CheckBox ID="CheckBox3" runat="server" Checked="True" Text=" " />
</td>
</tr>
<tr>
<td class="auto-style189">Address:</td>
<td class="auto-style165">
<asp:TextBox ID="TextBox4" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
</td>
<td class="auto-style191">City:</td>
<td class="auto-style165">
<asp:TextBox ID="TextBox5" runat="server" Width="182px" Enabled="False"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style188">State:</td>
<td class="auto-style171">
<asp:TextBox ID="TextBox15" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
</td>
<td class="auto-style190">ZipCode:</td>
<td class="auto-style171">
<asp:TextBox ID="TextBox6" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style179"><strong>Email Address:</strong></td>
<td class="auto-style180">
<asp:TextBox ID="TextBox17" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
</td>
<td class="auto-style180"> </td>
<td class="auto-style180"> </td>
</tr>
</table>
</div>
<div id="Comments" style="display: none;">
<table class="table_1">
<tr>
<td style="vertical-align: top;" class="auto-style169"><strong>Comment
<br />
For
<br />
Customer:</strong></td>
<td class="auto-style165" style="vertical-align: top">
<asp:TextBox ID="TComments" runat="server" Height="143px" TextMode="MultiLine" Width="697px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="vertical-align: top;" class="auto-style169"><strong>Comment
For<br />
Sales Person<br />
(Not visible on Quote)</strong></td>
<td class="auto-style165">
<asp:TextBox ID="TextBox19" runat="server" Height="143px" TextMode="MultiLine" Width="697px"></asp:TextBox>
</td>
</tr>
</table>
</div>

Your HTML does not include any id's. So when you reference by id:
var QuoteInfo = document.getElementById("QuoteInfo");
var ShippingInfo = document.getElementById("ShippingInfo");
var Comments = document.getElementById("Comments");
you need your html tag to also have that id.

Related

Refresh partial page on user control text change event

I have one Usercontrol Textbox with some radio buttons.
I want to refresh some of these buttons when I change the usercontrol textbox value.
In short, when I select Specific button it displays RM row & for All radio button selection it hides RM row. After selecting RM & checking Client radio button, it again displays two radio button below. By checking any of radio it displays the grid data below. For Prospect & Closed button it displays grid data below after checking it.
For all radio all the functionality is same except RM selection.
My all functionality is working as expected just need to add one more addition in it.
Now I want to refresh 5 radio buttons(Client, Prospect, Closed, Client, Family) which are below RM user control screen when I change the RM name from usercontrol textbox.
I tried using update panel but it couldn't work as it got mess for me so reverted all that changes. My current working code is as below:
<script type="text/javascript">
$110 = $;
$110(document).ready(function () {
//intial setting of panel
rdoBtnShowHidePanels();
$110("#trClient").hide();
$110("#btnSendSms").hide();
$110("#trCommMode").hide();
$110("input[type='radio'][name='First']").attr('checked', false);
$110("input[type='radio'][name='SelectRM']").change(function () {
$110("#trClient").hide();
$110("#jqxContact").hide();
$110("#trCommMode").hide();
if ($110("input[type='radio'][id='RdoSpecific']").is(":checked") == true) {
$110("input[type='radio'][name='First']").attr('checked', false);
$110("input[type='radio'][name='a']").attr('checked', false);
$110("#trRM").show();
$("input[id$=mcscRMSearch_txtSearch]").val('');
$110("input[type='radio'][name='First']").change(function () {
if ($110("input[type='radio'][id='RdoSpecific']").is(":checked") == true) {
if (ValidateRMSelection() == true) {
$110("#trRM").show();
if ($110("input[type='radio'][id='rdoClientAll']").is(":checked") == true) {
$110("#trClient").show();
$110("input[type='radio'][name='a']").change(function () {
$110("#hdnType").val("C");
$110("#jqxContact").show();
var getselectedrowindexes = $110('#jqxContact').jqxGrid('getselectedrowindexes');
$110('#jqxContact').jqxGrid('unselectrow', getselectedrowindexes);
$110('#jqxContact').jqxGrid('clearselection');
if ($110("input[type='radio'][id='RdoSpecific']").is(":checked") == true) {
BindGridBasedOnRadioButtons();
}
$110("#trCommMode").show();
return;
})
}
else {
$110("#hdnType").val("P");
$110("input[type='radio'][id='rdoclient']").prop("checked", false);
$110("input[type='radio'][id='rdofamily']").prop("checked", false);
$110("#trClient").hide();
$110("#jqxContact").show();
var getselectedrowindexes = $110('#jqxContact').jqxGrid('getselectedrowindexes');
$110('#jqxContact').jqxGrid('unselectrow', getselectedrowindexes);
$110('#jqxContact').jqxGrid('clearselection');
if ($110("input[type='radio'][id='RdoSpecific']").is(":checked") == true) {
BindGridBasedOnRadioButtons();
}
$110("#trCommMode").show();
return;
}
}
else {
alert("Select RM");
$110("#trClient").hide();
$110("#trCommMode").hide();
$110("#jqxContact").hide();
return;
}
}
})
}
else {
$110("#trRM").hide();
$110("#trCommMode").hide();
$110("input[type='radio'][name='First']").attr('checked', false);
$110("input[type='radio'][name='a']").attr('checked', false);
$110("input[type='radio'][name='First']").change(function () {
if ($110("input[type='radio'][id='rdoClientAll']").is(":checked") == true) {
$110("#jqxContact").hide()
$110("#trClient").show();
$110("input[type='radio'][name='a']").change(function () {
$110("#hdnType").val("C");
$110("#jqxContact").show();
var getselectedrowindexes = $110('#jqxContact').jqxGrid('getselectedrowindexes');
$110('#jqxContact').jqxGrid('unselectrow', getselectedrowindexes);
$110('#jqxContact').jqxGrid('clearselection');
BindGridBasedOnRadioButtons1();
$110("#trCommMode").show();
return;
})
}
else {
$110("#hdnType").val("P");
$110("input[type='radio'][id='rdoclient']").prop("checked", false);
$110("input[type='radio'][id='rdofamily']").prop("checked", false);
$110("#trClient").hide();
$110("#jqxContact").show();
var getselectedrowindexes = $110('#jqxContact').jqxGrid('getselectedrowindexes');
$110('#jqxContact').jqxGrid('unselectrow', getselectedrowindexes);
$110('#jqxContact').jqxGrid('clearselection');
BindGridBasedOnRadioButtons1();
$110("#trCommMode").show();
return;
}
})
}
})
<form id="Form1" method="post" runat="server">
<asp:ScriptManager ID="scmPhoneBook" runat="server">
</asp:ScriptManager>
<table id="Table1" cellspacing="1" cellpadding="0" width="100%" border="0">
<tr>
<td class="clsTitle" align="center" style="height: 25px">Contacts
</td>
</tr>
<tr>
<td class="clstd" align="left" style="width: 100%" colspan="2">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="clstdnext" align="left" style="width: 100%" colspan="2">
<asp:RadioButton ID="RdoSpecific" runat="server" GroupName="SelectRM" Text="Specific"></asp:RadioButton>
<asp:RadioButton ID="RdoAll" runat="server" GroupName="SelectRM" Text="All"></asp:RadioButton>
</td>
</tr>
<tr id="trRM">
<td class="clstd" width="2%">RM
</td>
<td class="clstd" width="98%">
<mwimcs:MultiColumnSearchControl
runat="server"
ID="mcscRMSearch"
CssClass="clsTextbox"
Width="300"
ControlType="137"
DataTextField="usr_name"
DataValueField="usr_id"
Top="-15px" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="clstdnext" align="left" style="width: 100%" colspan="2">
<asp:RadioButton ID="rdoClientAll" runat="server" GroupName="First" Text="Client"></asp:RadioButton>
<asp:RadioButton ID="RdoProspect" runat="server" GroupName="First" Text="Prospect"></asp:RadioButton>
<asp:RadioButton ID="RdoClosed" runat="server" GroupName="First" Text="Closed"></asp:RadioButton>
</td>
</tr>
<tr id="trClient">
<td class="clstd" align="left" style="width: 100%" colspan="2">
<asp:RadioButton ID="rdofamily" runat="server" GroupName="a" Text="Family"></asp:RadioButton>
<asp:RadioButton ID="rdoclient" runat="server" GroupName="a" Text="Client"></asp:RadioButton>
</td>
</tr>
<tr>
<td valign="top">
<div id="jqxContact"></div>
<asp:Panel ID="PnlClient" runat="server" Width="100%">
</asp:Panel>
</td>
<asp:DataGrid ID="dgCompany" runat="server" Width="100%" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" PageSize="25">
</asp:DataGrid>
</tr>
</table>
<br />
<table width="100%" cellpadding="0" cellspacing="1" border="0">
<tr height="10px">
<td class="clsLabel_err" colspan="2">
<asp:Label ID="lblErrorMsg" runat="server" CssClass="clsLabel_err"></asp:Label>
</td>
</tr>
<tr style="width: 100%" id="trCommMode">
<td class="clstdnext" style="width: 25%">Communication Mode:</td>
<td class="clstdnext" align="left" valign="middle">
<asp:RadioButtonList ID="rbtnlistSmsMail" runat="server" RepeatDirection="Horizontal"
Font-Names="Verdana" Font-Size="11px">
<asp:ListItem>
SMS
</asp:ListItem>
<asp:ListItem>
E-Mail
</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td colspan="2" id="pnlEmailDtls" runat="server">
<asp:Panel ID="pnlpnlEmailDtls" runat="server" Width="100%">
<table id="Table3" cellspacing="1" cellpadding="0" width="100%" border="0">
<tr>
<td class="clstd" style="width: 25%">Email From</td>
<td class="clsTd" style="width: 80%">
<cc1:MultiColumnComboBox ID="mmcEmail" runat="server" CssClass="clstd" HeaderCSS="clsReportTitle"
ItemsCSS="clstdnext" VerticalScrolling="True" DownArrowButtonCSS="clsButton"
DownArrowImageURL="url(Images/downarrow.gif)" DownArrowButtonHeight="12" DownArrowButtonWidth="20"
TextBoxCSS="clsTextbox">
<Columns>
<cc1:Column ColumnWidth="" DataField="email" KeyColumn="True" HeaderText="Email"></cc1:Column>
<cc1:Column ColumnWidth="" DataField="smtp" KeyColumn="False" HeaderText="SMTP"></cc1:Column>
</Columns>
</cc1:MultiColumnComboBox>
</td>
</tr>
<tr>
<td class="clstdnext" style="width: 20px">Subject</td>
<td class="clstdnext" style="width: 80px">
<asp:TextBox ID="txtSubject" runat="server" CssClass="clsTextbox" Width="327px">
</asp:TextBox>
</td>
</tr>
<tr>
<td class="clstd">Attachment 1)
</td>
<td class="clstd">
<input class="clsTextbox" id="fileupload1" style="width: 250px" type="file" size="48" runat="server"
name="fileupload1" />
</td>
</tr>
<tr>
<td class="clstdnext">Attachment 2)
</td>
<td class="clstdnext">
<input class="clsTextbox" id="fileupload2" style="width: 250px" type="file" size="48" runat="server"
name="fileupload2" />
</td>
</tr>
<tr>
<td class="clstd">Attachment 3)
</td>
<td class="clstd">
<input class="clsTextbox" id="fileupload3" style="width: 250px" type="file" size="48" runat="server"
name="fileupload3" />
</td>
</tr>
<tr>
<td class="clsReportTitle" align="center" style="width: 100%" colspan="2">Message
</td>
</tr>
<tr>
<%--<TD width="100%" colSpan=2>
<asp:TextBox id=txtMessage runat="server" CssClass="clsTextbox" Width="100%" TextMode="MultiLine" Height="250px"></asp:TextBox></TD>--%>
<td align="left" class="clstd" colspan="2">
<ftb:FreeTextBox ID="FreeTextBox1" EnableHtmlMode="false" ToolbarLayout="ParagraphMenu, FontFacesMenu, FontSizesMenu, FontForeColorsMenu,FontForeColorPicker, FontBackColorsMenu, FontBackColorPicker, Bold, Italic, Underline,Strikethrough, Superscript, Subscript|InsertImageFromGallery, CreateLink, Unlink, JustifyLeft, JustifyRight, JustifyCenter, JustifyFull,BulletedList, NumberedList, Indent, Outdent,Cut, Copy, Paste, Delete, Undo, Redo,Save,InsertRule, InsertDate,InsertTime,Preview"
Height="300px" runat="server" Width="100%">
</ftb:FreeTextBox>
</td>
</tr>
<tr>
<td style="width: 100%" class="clstd_btn" colspan="2">
<%--<input id="BtnSendEmail" type="button" class="clsButton" value="Send"/>--%>
<asp:Button ID="BtnSendEmail" runat="server" OnClientClick="return ValidationBeforeEmailSendClick();" CssClass="clsButton" Text="Send"></asp:Button>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
<tr>
<td colspan="2" id="pnlSmsDtls" runat="server">
<asp:Panel ID="pnlpnlSmsDtls" runat="server" Width="100%">
<table cellspacing="1" cellpadding="0" width="100%" border="0">
<tr>
<td class="clstd" style="width: 25%">SMS Type
</td>
<td class="clstd">
<asp:DropDownList ID="ddlSmsType" CssClass="clsCombobox" runat="server">
<asp:ListItem Value="0">---Select---</asp:ListItem>
<asp:ListItem Value="1">Upcoming maturity/due date</asp:ListItem>
<asp:ListItem Value="2">New product offerings</asp:ListItem>
<asp:ListItem Value="3">Pick of the day</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2" class="clstdnext">SMS Text
</td>
</tr>
<tr>
<td colspan="2" class="clstdnext" style="height: 40px">
<asp:TextBox ID="txtSmsText" runat="server" CssClass="clsTextbox" TextMode="MultiLine"
Width="100%" Height="100px">
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" class="clstd_btn">
<input type="button" id="btnGo" value="Save" class="clsButton" />
<%--<asp:Button ID="btnGo" runat="server" CssClass="clsButton" Text="Save" />--%>
<asp:Button ID="btnSendSms" runat="server" CssClass="clsButton" Text="Send SMS"
Width="72px"></asp:Button>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
<input type="hidden" id="hdnType" />
</form>
Its argent... kindly please help.
Thanks in advance.

Why no CSS showing after printing using Window.Print()?

I want to print one particular div in my page. And to do so I am using the following code:
<script type="text/javascript">
function printDiv(divID) {
var DocumentContainer = document.getElementById(divID);
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln('<!DOCTYPE html>');
WindowObject.document.writeln('<html><head>');
WindowObject.document.writeln('<style type="text/css" media="all">.labelalign {float: right !important;}.design {font-size: 16px;}.design1 {font-size: 15px;}.td {background-color: #A4A4A4;}</style>');
WindowObject.document.writeln('</head><body>');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.writeln('</body></html>');
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
<asp:Button ID="Btnpdfprint" runat="server" Text="Print to PDF" OnClientClick="javascript:printDiv('mydiv')" />
HTML Table:
<table style="width: 899px;" align="center" cellpadding="4" cellspacing="3">
<tr>
<td style="width: 50%;">
<%-- <asp:Label ID="lblcandidateid" runat="server" Text="Label" CssClass="design1" ></asp:Label>--%>
</td>
<td style="width: 50%">
<%--<asp:Image ID="candidateimg" runat="server" ImageUrl="img/avatar1_small.jpg" ImageAlign="Right" Width="90px" Height="83px" />--%></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design" style="background-color: #A4A4A4;">Personal Details</b>
<%-- <asp:Label ID="txtcandidatename" runat="server" Text="Label" CssClass="design1">
</asp:Label>--%>
</td>
</tr>
<tr>
<td><b class="design">Name: </b><asp:Label ID="txtcandidatename" runat="server" CssClass="design1" Text="Label"></asp:Label>
</td>
<td><b class="design">Nationality: </b><asp:Label ID="txtnationality" runat="server" CssClass="design1" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td><b class="design">Languages: </b><asp:Label ID="txtlanguage" runat="server" Text="Label" CssClass="design1"></asp:Label>
</td>
<td><b class="design">Current Address: </b><asp:Label ID="txtcurrentaddress" runat="server" CssClass="design1" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td><b class="design">Marital Status: </b><asp:Label ID="txtmaritalstatus" runat="server" Text="Label"></asp:Label>
</td>
<td><b class="design">Date of Birth: </b><asp:Label ID="txtdob" runat="server" Text="Label" CssClass="design1"></asp:Label>
</td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2" style="background-color: #A4A4A4;"><b class="design">Career Objective</b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtcandidateobjective" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2" style="background-color: #A4A4A4;"><b class="design">Career Profile</b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtcareerprofile" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design">Key Areas of Expertise</b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtskills" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design">Professional Experience</b></td>
</tr>
<tr>
<td>
<asp:Label ID="txtcompanyname" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
<td>
<asp:Label ID="txtdate" runat="server" Text="Label" CssClass="design1" align="right"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2"><i class="design">
<asp:Label ID="txttitle" runat="server" Text="Label" CssClass="design1"></asp:Label></i>
</td>
</tr>
<tr>
<td colspan="2"><b class="design"><i>Key Responsibilities</i></b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtkeyresponsibilities" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td colspan="2"><b class="design"><i>Key Achievements</i></b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtkeyachievements" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design">Education</b></td>
</tr>
<tr>
<td colspan="2"><b class="design">Education: </b>
<asp:Label ID="txteducation" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td colspan="2"><b class="design">Location: </b>
<asp:Label ID="txtlocation" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td colspan="2"><b class="design">Major: </b>
<asp:Label ID="txtmajor" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td colspan="2"><b class="design">Year of Passing: </b>
<asp:Label ID="txtpassing" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design">Certification</b></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="txtcertification" runat="server" Text="Label" CssClass="design1"></asp:Label></td>
</tr>
<tr>
<td class="td" style="border: solid 1px;" colspan="2"><b class="design">References</b></td>
</tr>
<tr>
<td>Will be presented upon request</td>
</tr>
</table>
I am getting like this into the printing window:
But this is my original design:
But when it prints it is not taking any CSS style specified for each label or TD. Please help me on this. Thanks.
Try creating the sytle element using document.createElement('style').
function printDiv(divID) {
var DocumentContainer = document.getElementById(divID);
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
var style = document.createElement('style');
var css = '.labelalign {float: right !important;}.design {font-size: 16px;}.design1 {font-size: 15px;}.td {background-color: #A4A4A4;}';
WindowObject.document.writeln('<!DOCTYPE html>');
WindowObject.document.writeln('<html><head>');
WindowObject.document.writeln('</head><body>');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.writeln('</body></html>');
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head = WindowObject.document.head || WindowObject.document.getElementsByTagName('head')[0];
head.appendChild(style);
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
Ok , here is your working code , i have added test table with small test style , updated to your html
<Button ID="Btnpdfprint" runat="server" Text="Print to PDF" OnClick="printDiv('mydiv')" />click</button>
<script type="text/javascript">
function printDiv(divID) {
var DocumentContainer = document.getElementById(divID);
var WindowObject = window.open('', 'PrintWindow', 'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln('<!DOCTYPE html>');
WindowObject.document.writeln('<html><head>');
WindowObject.document.writeln('<style type="text/css" media="all">#mydiv{color:red;font-size:30px; background-color: #1a4567 !important;-webkit-print-color-adjust: exact; }</style>');
WindowObject.document.writeln('</head><body>');
WindowObject.document.writeln('<div id="mydiv"><table><tr><td>table for test</td></tr></table></div>');
WindowObject.document.writeln('</body></html>');
WindowObject.document.close();
WindowObject.focus();
WindowObject.print();
WindowObject.close();
}
</script>
notes : i just replaced this line WindowObject.document.writeln(DocumentContainer.innerHTML);
with the html directly
and i have added small css attribute to the style
-webkit-print-color-adjust: exact;

how to count of datalist item (which is an image)

i want to count items image (ImageUploaded) in Datalist in javascript how can i do that.
<asp:DataList ID="DataListUploadedPhotos" ClientIDMode="Static" runat="server" RepeatDirection="Horizontal" RepeatColumns="3" CellPadding="10" CellSpacing="10" OnItemDataBound="DataListUploadedPhotos_ItemDataBound" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<table border="0" cellpadding="2" cellspacing="0" align="left" width="100%">
<tr> <td align="left" style="width:200px; height:30px">
<b>
<asp:Label ID="LabelImageTitle" runat="server" Text='<%#Eval("title")%>' Height="10px"></asp:Label>
</b> </td> <td align="right"> </td> </tr> <tr> <td align="center" colspan="2" style="background-color: #eeeeee; width: 260px; height: 260px" valign="middle">
<asp:Image ID="ImageUploaded" runat="server" ImageUrl='<%#"../upload/photos/LargeThumbs/"+Eval("fileName")%>'
AlternateText='<%#Eval("title")%>' ClientIDMode="Static" Style="border: 5px solid #eeeeee;" onclick='<%# "return ImageSelected(this.id, " + Eval("photoId") +",\"ContentPlaceHolder1_txtIds\");"%>' /></td>
</tr>
<tr>
<td>
<a href='<%#"../upload/photos/PopUpThumbs/"+Eval("fileName")%>'>
<asp:ImageButton ID="ImageButtonResultClose" runat="server" ImageUrl="~/images/enlarge.png" /> </a>
<asp:Label ID="LabelPhotoid" runat="server" Text='<%#Eval("photoId")%>'></asp:Label>
</td>
<td>
<asp:ImageButton ID="details" runat="server" ImageUrl="~/images/details.png" OnClick="details_Click"
CommandArgument='<%#Eval("photoId")%>'/>
</td></tr>
<tr>
<td>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
you need to count the items in the folder where you are uploading the image
Something like this
string mydir = #"C:\images\";
string[] files;
int numberofFiles;
files = Directory.GetFiles(mydir);
numberofFiles = files.Length;
string nextFileName = (numberofFiles + 1).ToString() + ".jpg";
Let me know if that helps
Give your image a class for example ClassName = "imgUploaded". if you use jQuery then the count of the img will be $(".imgUploaded").length

Open a ModalPopupExtender on an UpdatePanel using javascript

I'm trying to open a ModalPopup with JavaScript, and i've searched here on stackoverflow and the general advice seems be to use something like this:
$('#inputAdd').live("click", function () {
$('#addRow').show();
$find('<%=mpeIndications.BehaviorID %>').show();
});
Where #inputAdd is an html input image that i have in the ModalPopup, its objective is to show a row (#addRow) where a TextBox is shown. However, when i click on the #inputAdd button, it show the row, but then the ModalPopup hide, I think the reason maybe because there is an UpdatePanel that include the ModalPopup, I am right? In that case which may be a solution? I've putted some of the code I've in the .ascx. Thanks.
<table class="content-box">
<tr>
<td valign="top">
<asp:UpdatePanel runat="server" ID="upAppointments">
<ContentTemplate>
<table>
<tr>
<td>
<asp:Button runat="server" ID="btnIndicationsHidden" Style="display: none;" />
<asp:Panel runat="server" ID="pnlIndications" CssClass="modalPanel" Style="display: none;">
<table class="content-box">
<tr>
<td>
<table style="width: 100%;">
<tr>
<td>
<asp:Panel runat="server" ID="pnlShowCurrentIndication" Style="padding: 13px 8px 8px 8px">
<table style="width: 100%; border: 0;">
<tr>
<td style="width: 30%; vertical-align: top;" rowspan="2">
<asp:RadioButtonList runat="server" ID="gvProfiles" OnDataBound="gvProfiles_DataBound"
DataTextField="Name" DataValueField="Id" Style="white-space: nowrap;" />
</td>
<td style="padding-left: 10px;" class="contentBox">
<table style="width: 100%;">
<tbody id="showTable">
<tr>
<td id="indicacionestd" runat="server">
Indicaciones:
</td>
</tr>
<tr>
<td>
<asp:BulletedList ID="blIndicaciones" DataTextField="Valor" runat="server">
</asp:BulletedList>
</td>
</tr>
<tr>
<td id="contraindicacionestd" runat="server">
Contraindicaciones:
</td>
</tr>
<tr>
<td>
<asp:BulletedList ID="blContraindicaciones" DataTextField="Valor" runat="server">
</asp:BulletedList>
</td>
</tr>
</tbody>
<tbody style="display: none;" id="addRow">
<tr>
<td style="text-align: left; white-space: nowrap;" class="colSepGran">
Nombre:
</td>
</tr>
<tr class="filSepGranRA">
<td class="colSepGran">
<asp:TextBox runat="server" ID="txbName" CssClass="txtNoWidth" Width="150px" ToolTip="Especifique el nombre del perfil"></asp:TextBox>
<act:FilteredTextBoxExtender runat="server" ID="ftbeName" FilterMode="ValidChars"
FilterType="UppercaseLetters, LowercaseLetters, Custom" TargetControlID="txbName"
ValidChars="ñ Ñ ' á é í ó ú Á É Í Ó Ú ü Ü ." />
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;">
<table style="width: 100%;">
<tr>
<td>
</td>
<td>
<input type="image" src="../../App_Themes/Theme/Images/AppIcons/add.png/" id="inputAdd"
title="Adicionar perfil">
</td>
<td>
<input type="image" src="../../App_Themes/Theme/Images/AppIcons/add_document.png"
id="inputAddSimple" title="Adicionar indicación" />
</td>
<td>
<input type="image" src="../../App_Themes/Theme/Images/AppIcons/edit.png" id="inputEdit"
title="Editar perfil" />
</td>
<td>
<asp:ImageButton runat="server" ID="imbRemoveProfile" ToolTip="Eliminar perfil" ImageUrl="~/App_Themes/Theme/Images/AppIcons/delete.png" />
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
<act:ModalPopupExtender ID="mpeIndications" runat="server" PopupControlID="pnlIndications"
BackgroundCssClass="modalBackground" TargetControlID="btnIndicationsHidden" CancelControlID="imbCloseIndications"
BehaviorID="mpeIndications">
</act:ModalPopupExtender>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
Then try this approach:
Add a hidden link for ModalPopup Extender to attach to(which will NEVER be used)
<a href="#" style="display:none;visibility:hidden;"
onclick="return false" ID="dummyLink" runat="server">dummy</a>
Add the ID of the hidden link to the ModalPopupExtender
<act:ModalPopupExtender ID="mpeIndications" runat="server" PopupControlID="pnlIndications"
BackgroundCssClass="modalBackground"
TargetControlID="dummyLink"
CancelControlID="imbCloseIndications"
BehaviorID="mpeIndications">
Showing the modal popup
$find('MyMPE').show();
http://www.geekzilla.co.uk/View38736C2B-BAD3-418A-A5B0-DAC4F1A5A83A.htm
Model Dialog Asp.Net With Jquery

how to show msgbox on button click event if i have some disabled checkboxes and user forgot to check checkboxes

i m using asp.net Usercontrols How to show alert msgbox if user doesn't select atleast minimun 1 checkbox from asp.net checkboxes
if i have disabled some checkboxes on page load event then after user forgot to check checkboxes and click on button then still msgbox will popup "you haven't select checkboxes"
please edit my this code ...to show msg box on button click event if i have disabled checkboxes and if user haven't select any of the checkbox
<%# Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb" Inherits="_35seater_WebUserControl" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<div id="s" style="width: 499px">
<asp:Panel ID="Panel1" runat="server" Width="77px">
<table class="style66">
<tr>
<td class="style68" rowspan="2">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/streer.gif" />
</td>
<td rowspan="5" style="background-color: #E4E4E4">
</td>
<td>
</td>
<td>
<span class="style106">
<asp:CheckBox ID="CheckBox1" runat="server" ForeColor="White" Height="33px"
Text="1" Width="33px" />
<cc1:ToggleButtonExtender ID="CheckBox1_ToggleButtonExtender" runat="server"
CheckedImageUrl="images/selected.gif"
DisabledUncheckedImageUrl="images/disabled.gif" Enabled="True" ImageHeight="33"
ImageWidth="33" TargetControlID="CheckBox1"
UncheckedImageUrl="images/booked.gif"></cc1:ToggleButtonExtender>
</span>
</td>
<td>
<span class="style106">
<asp:CheckBox ID="CheckBox3" runat="server" ForeColor="White" Height="33px"
Text="3" Width="33px" />
<cc1:ToggleButtonExtender ID="CheckBox3_ToggleButtonExtender" runat="server"
CheckedImageUrl="images/selected.gif"
DisabledUncheckedImageUrl="images/disabled.gif" Enabled="True" ImageHeight="33"
ImageWidth="33" TargetControlID="CheckBox3"
UncheckedImageUrl="images/booked.gif"></cc1:ToggleButtonExtender>
</span>
</td>
<td>
<span class="style106">
<asp:CheckBox ID="CheckBox10" runat="server" ForeColor="White" Height="33px"
Text="10" Width="33px" />
<cc1:ToggleButtonExtender ID="CheckBox10_ToggleButtonExtender" runat="server"
CheckedImageUrl="images/selected.gif"
DisabledUncheckedImageUrl="images/disabled.gif" Enabled="True" ImageHeight="33"
ImageWidth="33" TargetControlID="CheckBox10"
UncheckedImageUrl="images/booked.gif"></cc1:ToggleButtonExtender>
</span>
</td>
<td>
</tr>
</table>
<hr style="width: 494px; height: -15px" />
<table class="style99" style="text-align: center; height: 10px;">
<tr class="style102">
<td class="style103" style="text-align: center; " colspan="3">
<table class="style113">
<tr>
<td class="style116">
<asp:Label ID="Label20" runat="server" style="font-weight: 700; color: #990000; font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="Select Boarding Point :"></asp:Label>
</td>
<td class="style115">
<asp:Label ID="Label23" runat="server"
style="font-weight: 700; color: #990000; font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="Select Dropping Point :"></asp:Label>
<asp:Label ID="Label24" runat="server" ForeColor="White"
style="font-size: xx-small" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="style114" style="text-align: right">
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource1" DataTextField="bd_time" DataValueField="bd_time"
style="margin-left: 0px; " Width="240px">
<asp:ListItem>Choose...</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [bd_time] FROM [boardingpt] WHERE ([service] = #service)">
<SelectParameters>
<asp:ControlParameter ControlID="Label22" Name="service" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource2" DataTextField="dp_time" DataValueField="dp_time"
style="margin-left: 0px; " Width="240px">
<asp:ListItem>Choose...</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT [dp_time] FROM [droppingpt] WHERE ([service] = #service)">
<SelectParameters>
<asp:ControlParameter ControlID="Label22" Name="service" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="style114" colspan="2" style="text-align: center; padding-top: 12px;">
<asp:ImageButton ID="ImageButton1" OnClientClick ="return checkboxChecked();" runat="server"
ImageUrl="~/images/redContinueButton.gif" />
</td>
</tr>
<tr>
<td class="style114" colspan="2" style="text-align: left">
<div style="visibility: hidden; overflow: hidden">
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource4" DataTextField="sel_seat"
DataValueField="sel_seat" Font-Size="Smaller" ForeColor="Maroon"
RepeatDirection="Horizontal" RepeatLayout="Flow">
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="CheckBoxList2" runat="server"
DataSourceID="SqlDataSource3" DataTextField="seats" DataValueField="seats"
Font-Size="Smaller" ForeColor="Maroon" RepeatDirection="Horizontal"
RepeatLayout="Flow">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT TOP 1 [seats], [id], [dates], [service]
FROM a1_holds
WHERE (dates = #dates) AND (service = #service) ORDER BY [id] DESC">
<SelectParameters>
<asp:ControlParameter ControlID="Label25" Name="dates" PropertyName="Text" />
<asp:ControlParameter ControlID="Label22" Name="service" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT sel_seat
FROM a1_ticket
WHERE (journey_date = #journey_date) AND (serv_code = #serv_code)">
<SelectParameters>
<asp:ControlParameter ControlID="Label25" Name="journey_date"
PropertyName="Text" />
<asp:ControlParameter ControlID="Label22" Name="serv_code"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label25" runat="server" Font-Size="Smaller" Text="Label"></asp:Label>
<asp:Label ID="Label26" runat="server" Font-Size="Smaller" Text="Label"></asp:Label>
<asp:Label ID="Label27" runat="server" Font-Size="Smaller"></asp:Label>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr class="style102">
<td class="style100">
<asp:TextBox ID="TextBox1" runat="server" BorderColor="White"
BorderStyle="None" BorderWidth="0px" ReadOnly="True"
style="font-size: small; text-align: center; font-weight: 700; color: #FFFFFF;"></asp:TextBox>
</td>
<td class="style112">
<asp:Label ID="Label17" runat="server"
style="font-size: small; font-weight: 700; color: #FFFFFF;"></asp:Label>
</td>
<td class="style110">
<asp:Label ID="Label18" runat="server"
style="font-size: small; font-weight: 700; color: #FFFFFF;"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</div>
<script type="text/javascript" language="javascript">
function checkboxChecked(){
var checked=false;
var allInputs = document.getElementsByTagName("input");
var noOfChkBox = 0; // number of check box
var noOfDisabledChkBox = 0; // number of disabled check box
for(var i=0; i<allInputs.length; i++){
var chk=allInputs[i];
if(chk.type == "checkbox"){
noOfChkBox++;
if(chk.disabled){
noOfDisabledChkBox++;
}
if(chk.checked){
checked=true;
break;
}
}
}
if(noOfDisabledChkBox===noOfChkBox)
{
checked=true;
}
if(!checked)
alert("OOps! You haven't select checkboxes");
return checked;
}
</script>
I have modified your js.Please chk and revert if it works
<script type="text/javascript" language="javascript">
function checkboxChecked(){
var checked=false;
var allInputs = document.getElementsByTagName("input");
var noOfChkBox = 0; // number of check box
var noOfDisabledChkBox = 0; // number of disabled check box
for(var i=0; i<allInputs.length; i++){
var chk=allInputs[i];
if(chk.type == "checkbox"){
noOfChkBox++;
if(chk.disabled){
noOfDisabledChkBox++;
}
if(chk.checked){
checked=true;
break;
}
}
}
if(noOfDisabledChkBox===noOfChkBox)
{
checked=true;
}
if(!checked)
alert("OOps! You haven't select checkboxes");
return checked;
}
</script>

Categories