RSS

Monthly Archives: May 2011

removing header and footer while printing


First Solution

For IE & FireFox

<a href=”javascript:window.print();”>

<img title=”Print this page” src=”/images/print_icon.jpg”

border=”0″></a>

Second Solution

this is recommended code

<a href=”#”  onclick=”window.print()” onmouseup=”document.getElementById(‘header’).style.display=’None’;document.getElementById(‘footer’).style.display=’None'”> Print </a>

Third Solution

removing header and footer while printing the page through coding?

With C# Language

I have the code for making the header and footer to be removed dynamically while printing

public void IESetupFooter()

{

string strKey = “Software\\Microsoft\\Internet Explorer\\PageSetup”;

bool bolWritable = true;

string strName = “footer”;

object oValue = “”;

RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable);

Console.Write(strKey);

oKey.SetValue(strName, oValue);

oKey.Close();

}

public void IESetupHeader()

{

string strKey1 = “Software\\Microsoft\\Internet Explorer\\PageSetup”;

bool bolWritable1 = true;

string strName = “header”;

object oValue1 = “”;

RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey1, bolWritable1);

Console.Write(strKey1);

oKey.SetValue(strName, oValue1);

oKey.Close();

}

With Vb.Net

Public Sub IESetupFooter()
	Dim strKey As String = "Software\Microsoft\Internet Explorer\PageSetup"
	Dim bolWritable As Boolean = True
	Dim strName As String = "footer"
	Dim oValue As Object = ""
	Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable)
	Console.Write(strKey)
	oKey.SetValue(strName, oValue)
	oKey.Close()
End Sub
Public Sub IESetupHeader()
	Dim strKey1 As String = "Software\Microsoft\Internet Explorer\PageSetup"
	Dim bolWritable1 As Boolean = True
	Dim strName As String = "header"
	Dim oValue1 As Object = ""
	Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey1, bolWritable1)
	Console.Write(strKey1)
	oKey.SetValue(strName, oValue1)
	oKey.Close()
End Sub

Directly Remove from Browser

Internet Explorer 7

 

 

Firefox

 

 

 

Advertisements
 
7 Comments

Posted by on May 31, 2011 in ASP Dot Net C#, Java Script, Vb.Net

 

Tags: , , ,

Create FirendlyUrl from Text


Aspx File

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
<script src=”js/Utility.js” type=”text/javascript”></script>
<script type=”text/javascript”>

function updateFirendlyUrl() {

if (document.getElementById(‘<%=txtfriendlyUrl.ClientID%>’).value == “”) {
var URL = ParseURL(document.getElementById(“<%=txtPageName.ClientID %>”).value);
if (URL != “”) document.getElementById(‘<%=txtfriendlyUrl.ClientID%>’).value = URL;
}
}

</script>
</head>

<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr><td>
Name:
</td>
<td>
<asp:TextBox ID=”txtPageName” runat=”server”></asp:TextBox>
</td>
</tr>
<tr><td>
Result url:
</td>
<td>
<asp:TextBox ID=”txtfriendlyUrl” runat=”server”></asp:TextBox>
</td>
</tr>
<tr><td colspan=”2″ align=”right”>
<input type=”button” name=”button” id=”button” onclick=”updateFirendlyUrl()” value=”Submit” />
</td></tr>
</table>

</div>
</form>
</body> </html>

js File

Utility.js

function ParseURL(URL) {
var title = URL;
/*var idx = title.indexOf(” & “);
while (idx > -1) {
title = title.replace(” & “, “-“);
idx = title.indexOf(” & “);
}
idx = title.indexOf(“&”);
while (idx > -1) {
title = title.replace(“&”, “”);
idx = title.indexOf(“&”);
}
idx = title.indexOf(” “);
while (idx > -1) {
title = title.replace(” “, “-“);
idx = title.indexOf(” “);
}*/
/*
title = title.replace(/ & /g, “-“)
title = title.replace(/&/gi, “”)
title = title.replace(/ /g, “-“)
title = title.replace(/@/gi, “”)
*/
title = title.replace(/&amp;/gi, “”)
title = title.replace(/ /g, “-“)

title = title.replace(/[^a-zA-Z 0-9 -]+/g, ”);

if (title != “”)
return “/” + title + “.aspx”;

}

function GetTitleFromFileName(Control, txtPageName) {
if (Control) {
var arr1 = Control.value.split(“\\”);
var arr2 = arr1[arr1.length – 1].split(“.”);
document.getElementById(txtPageName).value = arr2[0];
}
}

 
Leave a comment

Posted by on May 26, 2011 in Vb.Net

 

Tags: ,

Send File With attatchement Link in E-Mail


Public Sub SendEmail(ByVal EmailTo As String, ByVal EmailCC As String, ByVal EmailBCC As String, ByVal EmailSubject As String, ByVal EmailBody As String, ByVal EmailFrom As String)
Dim smtpClient As New SmtpClient()
Try
If AppSettings(“ServerName”) <> “” Then
smtpClient.Host = AppSettings(“ServerName”)
If (AppSettings(“ServerName”).Length > 0) Then
smtpClient.Port = AppSettings(“smtpPort”)
End If
If (AppSettings(“smtpUser”).Length > 0) Then
smtpClient.Credentials = New NetworkCredential(AppSettings(“smtpUser”), AppSettings(“smtpPassword”))
End If
Dim emailMessage As New MailMessage()
emailMessage.To.Add(New MailAddress(EmailTo))
If EmailCC <> “” Then
emailMessage.CC.Add(New MailAddress(EmailCC))
End If
If EmailBCC <> “” Then
emailMessage.Bcc.Add(New MailAddress(EmailBCC))
End If
‘smtpClient.DeliveryMethod = smtpClient.PickupDirectoryLocation

emailMessage.From = New MailAddress(EmailFrom)
emailMessage.Body = EmailBody
emailMessage.Subject = EmailSubject
emailMessage.IsBodyHtml = True
emailMessage.Priority = MailPriority.Normal
If Not fu_Resume Is Nothing Then
If fu_Resume.HasFile Then
emailMessage.Attachments.Add(New Attachment(fu_Resume.PostedFile.InputStream, fu_Resume.FileName))
End If
End If
‘For Coverletter Attachement
If Not fu_CoverLetter Is Nothing Then
If fu_CoverLetter.HasFile Then
emailMessage.Attachments.Add(New Attachment(fu_CoverLetter.PostedFile.InputStream, fu_CoverLetter.FileName))
End If
End If
smtpClient.Send(emailMessage)
End If
Catch ex As Exception
‘Response.Redirect(“ErrorPage.aspx”)
‘return nothing
End Try
End Sub

 
Leave a comment

Posted by on May 25, 2011 in Vb.Net

 

Tags: ,

Dynamic change Image from Database after Page Refresh


Dynamic change and load Image from Database after Page Refresh with Dropdownlist

Javascript Function

<script language=”JavaScript” type=”text/javascript”>

function showText() {

var ddlReport = document.getElementById(“DropDownList1”);

var Text = ddlReport.options[ddlReport.selectedIndex].text;

var theImages = new Array()

for (var iter = 0; iter < ddlReport.options.length; iter++) {

theImages[iter] = ddlReport.options[iter].value;

} // end for loop

//  alert(theImages)

var j = 0

var p = theImages.length;

var whichImage = Math.round(Math.random() * (p – 1));

for (m = whichImage; m <= whichImage; m++) {

//               alert(theImages[whichImage])

document.write(theImages[whichImage]);

}

}

</script>

Call Javascrit Function from Body Tag

<script language=”javascript” type=”text/javascript”>showText();</script>

<form id=”frm” runat=”server”>

<div style=”visibility:hidden”>

<uc:TestimonialDDL ID=”CTR_TestimonialDDL” runat=”server”  />

</div>

</form>

Server Side Call Funtion at Page Load

Page.ClientScript.RegisterStartupScript(Me.GetType(), “Script”, “showText();”,

User Control

TestimonialDDL.ascx

<%@ Control Language=”VB” AutoEventWireup=”false” CodeFile=”TestimonialDDL.ascx.vb”

Inherits=”Controls_TestimonialDDL” %>

<select id=”DropDownList1″ name=”DropDownList1″>

<%= GetOption()%>

</select>

TestimonialDDL.vb

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(PassID Here)

End Function

The Problem with Dropdown the image not place accurately on page because drobdown also gain space so disturb the Page. The HiddenField is Comfortable not disturb page

Dynamic load Image after Page Refresh with HiddenField from Database

Javascript Function

<script language=”JavaScript” type=”text/javascript”>

function showText() {

//            var listString = document.getElementById(‘HiddenField1’).value;

var listString = document.getElementById(‘<%= HiddenField1.ClientID %>’).value

var listArray = listString.split(‘|’);

for (var i = 0; i < listArray.length; i++) {

listArray[i];

}

var j = 0

var p = listArray.length;

var whichImage = Math.round(Math.random() * (p – 1));

for (m = whichImage; m <= whichImage; m++) {

document.write(listArray[whichImage]);

}

}

</script>

Body

<div class=”testimonails”>

<script language=”javascript” type=”text/javascript”>showText();</script>

<form id=”frm” runat=”server”>

<asp:HiddenField ID=”HiddenField1″ runat=”server” />

</form>

</div>

File Codebehid Code

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(Page, “/Global.aspx”, “/testimonails.aspx”)

End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

HiddenField1.Value = GetOption()

Page.ClientScript.RegisterStartupScript(Me.GetType(), “Script”, “showText();”, True)

End Sub

Write this code to make Classes and Split the source content

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(PassID Here)

End Function

Public Shared Function GetRelatedDocuments(ByVal Documentid As Int32) As DataTable

Dim sqlObj As New SQLManager

Dim hParams As New Hashtable

hParams.Add(“@sectionID”, Documentid

Return sqlObj.getDataTableSP(“get_DocumentsContent”, hParams)

End Function

Public Shared Function GetDropDownOption(ByVal Documentid As Int32) As String

Dim strMainMenu As New StringBuilder

Dim docInfo As DataTable = DocumentDAL.GetRelatedDocuments(Documentid)

If Not docInfo Is Nothing Then

strMainMenu.Append(DropDownOption(docInfo))

End If

Return strMainMenu.ToString()

End Function

Private Shared Function DropDownOption(ByVal docInfo As DataTable) As String

Dim strTemp As New StringBuilder()

If docInfo.Rows.Count > 0 Then

For dtRowcount As Int32 = 0 To docInfo.Rows.Count – 1

If dtRowcount = docInfo.Rows.Count – 1 Then

strTemp.Append(RemoveParagraphTagOp(docInfo.Rows(dtRowcount)(“Content”)))

Else

strTemp.Append(RemoveParagraphTagOp(docInfo.Rows(dtRowcount)(“Content”)))

End If

Next

End If

Return strTemp.ToString()

End Function

Public Shared Function RemoveParagraphTagOp(ByVal strContent As String) As String

Dim str As String = “”

Dim link As String = “”

Dim ListOptions As New StringBuilder()

Dim strHref As String = “”

str = strContent

str = RemoveCommentContent(strContent)

If Not str = Nothing Then

Dim tmpStr As String = “”

Dim startIndex As Integer = 0

Dim endIndex As Integer = 0

str = Replace(Replace(str, “</ a>”, “</a>”), “< /a>”, “</a>”)

str = Replace(Replace(str, “</ A>”, “</A>”), “< /A>”, “</A>”)

str = Replace(Replace(str, “</ img>”, “</img>”), “< /img>”, “</img>”)

str = Replace(Replace(str, “</ img>”, “</img>”), “< /img>”, “</img>”)

str = Replace(Replace(str, “</ br>”, “”), “< /br>”, “”)

str = Replace(Replace(str, “</ br>”, “”), “”, “”)

str = Replace(Replace(str, “</br>”, “”), “<br>”, “”)

tmpStr = str.ToLower

While tmpStr.Contains(“<a”)

startIndex = tmpStr.IndexOf(“<a”)

endIndex = ((tmpStr.IndexOf(“</a>”) + 4) – tmpStr.IndexOf(“<a”))

link = str.Substring(startIndex, endIndex)

str = str.Remove(startIndex, endIndex)

tmpStr = tmpStr.Remove(startIndex, endIndex)

strHref = link

strHref = strHref.Remove(strHref.IndexOf(“>”), strHref.Length – strHref.IndexOf(“>”))

strHref = strHref.Remove(0, strHref.LastIndexOf(“href=”) + 5)

If (strHref.Substring(0, 1) = Chr(34)) Then

strHref = strHref.Remove(0, 1)

End If

If (strHref.Substring(strHref.Length – 1, 1) = Chr(34)) Then

strHref = strHref.Remove(strHref.Length – 1, 1)

End If

‘ListOptions.Append(“<option value='” + link + “‘>” & strHref & “</option>”)

ListOptions.Append(link & “|”)

End While

End If

Return ListOptions.ToString()

End Function

 
Leave a comment

Posted by on May 25, 2011 in Vb.Net

 

Tags: , , ,

Validation of control with JavaScript in popup window


Validation of control with JavaScript in popup window

Css

.input{

width:320px; margin:0 0 6px 0;

}

.label1{

display:block; float:left; width:160px; text-align:right; margin:0; padding:3px 10px 0 0;

}

JavaScript Function (Client Side)

<script language=”JavaScript” type=”text/JavaScript”>

<!–

function MM_findObj(n, d) { //v4.01

//n=”ctl00_ContentPlaceHolder1_” + n;

var p, i, x; if (!d) d = document; if ((p = n.indexOf(“?”)) > 0 && parent.frames.length) {

d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);

}

if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];

for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);

if (!x && d.getElementById) x = d.getElementById(n); return x;

}

function MM_validateForm() { //v4.0

var i, p, q, nm, test, num, min, max, errors = ”, args = MM_validateForm.arguments;

for (i = 0; i < (args.length – 2); i += 3) {

test = args[i + 2]; val = MM_findObj(args[i]);

if (val) {

nm = val.name; ; if ((val = val.value) != “”) {

if (test.indexOf(‘isEmail’) != -1) {

p = val.indexOf(‘@’);

if (p < 1 || p == (val.length – 1)) errors += ‘- ‘ + nm + ‘ must contain an e-mail address.\n’;

} else if (test != ‘R’) {

num = parseFloat(val);

if (isNaN(val)) errors += ‘- ‘ + nm + ‘ must contain a number.\n’;

if (test.indexOf(‘inRange’) != -1) {

p = test.indexOf(‘:’);

min = test.substring(8, p); max = test.substring(p + 1);

if (num < min || max < num) errors += ‘- ‘ + nm + ‘ must contain a number between ‘ + min + ‘ and ‘ + max + ‘.\n’;

}

}

} else if (test.charAt(0) == ‘R’) errors += ‘- ‘ + nm + ‘ is required.\n’;

}

} if (errors) alert(‘The following error(s) occurred:\n’ + errors);

document.MM_returnValue = (errors == ”);

}

//–>

function ShowTextFocus(obj, size, ids) {

if (obj.value.length == size) {

document.getElementById(ids).focus();

}

}

</script>

Form (Client Side)

<form id=”info” runat=”server”>

<br />

<asp:Panel ID=”pnlInfo” runat=”server” Visible=”true”>

<label>

Name: *</label>

<input name=”Name” type=”text” value=”” style=”width: 190px” />

<br />

<label>

Email: *</label>

<input type=”text” name=”Email” style=”width: 190px” />

<br />

<label>

Daytime Phone:*</label>

<input type=”text” name=”Day_Phone_1_1″ id=”Day_Phone_1_1″ size=”3″ maxlength=”3″

onkeyup=”ShowTextFocus(this,3,’Day_Phone_1_2′);” style=”width: 50px” />

<input type=”text” name=”Day_Phone_1_2″ id=”Day_Phone_1_2″ size=”3″ maxlength=”3″

onkeyup=”ShowTextFocus(this,3,’Day_Phone_1_3′);” style=”width: 50px” />

<input type=”text” name=”Day_Phone_1_3″ id=”Day_Phone_1_3″ size=”4″ maxlength=”4″

onkeyup=”ShowTextFocus(this,4,’Evening_Phone_1_1′);” style=”width: 50px” />

<br />

<label>

Evening Phone:

</label>

<input type=”text” name=”Evening_Phone_1_1″ id=”Evening_Phone_1_1″ size=”3″ maxlength=”3″

onkeyup=”ShowTextFocus(this,3,’Evening_Phone_1_2′);” style=”width: 50px” />

<input type=”text” name=”Evening_Phone_1_2″ id=”Evening_Phone_1_2″ size=”3″ maxlength=”3″

onkeyup=”ShowTextFocus(this,3,’Evening_Phone_1_3′);” style=”width: 50px” />

<input type=”text” name=”Evening_Phone_1_3″ id=”Evening_Phone_1_3″ size=”4″ maxlength=”4″

style=”width: 50px” />

<br />

<label>

Street Address: *

</label>

<input type=”text” name=”Street_Address” style=”width: 190px” />

<br />

<label>

City:*

</label>

<input name=”City” type=”text” value=”” style=”width: 190px” />

<br />

<label>

State:*

</label>

<select name=”ddlState” style=”width: 100px”>

<option value=”AL”>AL</option>

<option value=”AK”>AK </option>

<option value=”AR”>AR </option>

<option value=”AZ”>AZ </option>

<option value=”CA”>CA </option>

<option value=”CO”>CO </option>

<option value=”CT”>CT </option>

<option value=”DC”>DC </option>

<option value=”DE”>DE </option>

<option value=”FL”>FL </option>

<option value=”GA”>GA </option>

<option value=”HI”>HI </option>

<option value=”ID”>ID </option>

<option value=”IA”>IA </option>

<option value=”IL”>IL </option>

<option value=”IN”>IN </option>

<option value=”KS”>KS </option>

<option value=”KY”>KY </option>

<option value=”LA”>LA </option>

<option value=”MA”>MA </option>

<option value=”MD”>MD </option>

<option value=”ME”>ME </option>

<option value=”MI”>MI </option>

<option value=”MO”>MO </option>

<option value=”MN”>MN </option>

<option value=”MS”>MT </option>

<option value=”MT”></option>

<option value=”NC”>NC </option>

<option value=”ND”>ND </option>

<option value=”NE”>NE </option>

<option value=”NH”>NH </option>

<option value=”NJ”>NJ </option>

<option value=”NM”>NM </option>

<option value=”NY”>NY </option>

<option value=”NV”>NV </option>

<option value=”OH”>OH </option>

<option value=”OK”>OK </option>

<option value=”OR”>OR </option>

<option value=”PA”>PA </option>

<option value=”RI”>RI </option>

<option value=”SC”>SC </option>

<option value=”SD”>SD </option>

<option value=”TN”>TN </option>

<option value=”TX”>TX </option>

<option value=”UT”>UT </option>

<option value=”VA”>VA </option>

<option value=”VT”>VT </option>

<option value=”WA”>WA </option>

<option value=”WI”>WI </option>

<option value=”WV”>WV </option>

<option value=”WY”>WY </option>

</select>

<br />

<label>

Zip:*

</label>

<input name=”Zip” type=”text” value=”” style=”width: 190px” />

<br />

<label style=”text-align: right”>

How did you hear about us?:</label>

<input name=”HHAU” type=”text” value=”” style=”width: 190px” />

<br />

<br />

<label>

Message:

</label>

<textarea id=”txtAdtRmrks” name=”txtAdtRmrks” rows=”7″ cols=”30″></textarea>

<div style=”text-align: center”>

<br />

<input name=”Submit” type=”submit” id=”btnSubmit” runat=”server” onclick=”MM_validateForm(‘Name’,”,’R’,’Email’,”,’RisEmail’,’Day_Phone_1_1′,”,’RisNum’,’Day_Phone_1_2′,”,’NisNum’,’Day_Phone_1_3′,”,’RisNum’,’Evening_Phone_1_1′,”,’NisNum’,’Evening_Phone_1_2′,”,’NisNum’,’Evening_Phone_1_3′,”,’NisNum’,’Street_Address’,”,’R’,’City’,”,’R’,’Zip’,”,’R’);return document.MM_returnValue”

value=”Submit” />

<input id=”Reset1″ type=”reset” value=”Reset” />

</div>

<br />

<br />

<strong>* </strong>Fields are required.

</asp:Panel>

</form>

Server Side or Code Behind

The value of this field code behind

Dim strName As String = HttpUtility.HtmlEncode(Trim(Request.Form(“name”)))

Dim strEmail As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Email”)))

Dim strDay_Phone_1_1 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_1”)))

Dim strDay_Phone_1_2 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_2”)))

Dim strDay_Phone_1_3 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Day_Phone_1_3”)))

Dim stEvening_Phone_1_1 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_1”)))

Dim strEvening_Phone_1_2 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_2”)))

Dim strEvening_Phone_1_3 As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Evening_Phone_1_3”)))

Dim strStreet_Address As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Street_Address”)))

Dim strCity As String = HttpUtility.HtmlEncode(Trim(Request.Form(“City”)))

Dim strDropDownState As String = HttpUtility.HtmlEncode(Trim(Request.Form(“ddlState”)))

Dim strZip As String = HttpUtility.HtmlEncode(Trim(Request.Form(“Zip”)))

Dim strHHAU As String = HttpUtility.HtmlEncode(Trim(Request.Form(“HHAU”)))

Dim strMessage As String =HttpUtility.HtmlEncode(Trim(Request.Form(“txtAdtRmrks”)))

 
Leave a comment

Posted by on May 17, 2011 in Java Script, Vb.Net

 

Tags: ,

Mail send with File Attachment with vb.net


Uploaded File send  Email with Attachment

just add this code before send method  like

smtpClient.Send(emailMessage)

fu_Resume  the name of Fileupload Control

If Not fu_Resume Is Nothing Then
If fu_Resume.HasFile Then
emailMessage.Attachments.Add(New Attachment(fu_Resume.PostedFile.InputStream, fu_Resume.FileName))
End If
End If

 
Leave a comment

Posted by on May 17, 2011 in Vb.Net

 

Tags: ,

TextArea control manage Enter,Space Character with vb.net


if you want to save your TextArea or Text with Multitextmode and you manage the Enter ,Space Character

Then you use this Function and just you pass first text box value before save.

like

For Html Control

Dim strMessage As String = GetMessage(HttpUtility.HtmlEncode(Trim(Request.Form(“txtAdtRmrks”))))

For SERVER  Control aspx control

Dim strMessage As String= GetMessage(txtcomments.text)

Public Shared Function GetMessage(ByVal obj As Object) As String
Dim str As String = “”
Dim lbl As New HtmlGenericControl
If Not obj Is Nothing Then
str = obj.ToString
str = Replace(str, vbCrLf, “<br />”)
lbl.InnerHtml = str
Return lbl.InnerText.ToString
Else
Return “”
End If
End Function

 
1 Comment

Posted by on May 17, 2011 in Vb.Net

 

Tags: , ,