Click here to Skip to main content
15,884,388 members

N!dh!sh - Professional Profile



Summary

    Blog RSS
198
Authority
7
Debator
63
Editor
15
Enquirer
17
Organiser
400
Participant
0
Author
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralExport Pin
N!dh!sh13-Nov-12 6:48
N!dh!sh13-Nov-12 6:48 
GeneralGridview Pin
N!dh!sh10-Oct-11 4:57
N!dh!sh10-Oct-11 4:57 
GeneralCode Tips 3 [modified] Pin
N!dh!sh12-Aug-11 3:47
N!dh!sh12-Aug-11 3:47 
GeneralCodeTips 2 [modified] Pin
N!dh!sh4-Jul-11 0:53
N!dh!sh4-Jul-11 0:53 
GeneralResize uploaded image [modified] Pin
N!dh!sh1-Jul-11 0:40
N!dh!sh1-Jul-11 0:40 
GeneralUseful Links [modified] Pin
N!dh!sh30-May-11 21:19
N!dh!sh30-May-11 21:19 
GeneralCode Tips [modified] Pin
N!dh!sh29-May-11 21:23
N!dh!sh29-May-11 21:23 
1) window.showModalDialog
2) Date validation using javascript
3) To fire validation summary before showing an alert (Page_ClientValidate())
4) Javascript to detect browser and screen height to set height of a div
5) Check whether a textbox value is null or ""
6) Export contents in a gridview in excel format
7) To retrieve selected value and text of a dropdownlist using javascript
8) To allow only integer values in an asp textbox
9) To restrict drop and count characters on 'copy paste' in a textbox
10) Encrypt and Decrypt
11) Without 3 tier architecture
------------------------------------------------------------------------------------------
1) window.showModalDialog
function Edit(ID)
{
var height = 140;
var width = 400;
var sizestring = 'dialogHeight:' + height + 'px;dialogWidth:' + width + 'px;center:Yes;scroll:No;status:No;edge:Raised;';
var retValue = window.showModalDialog('AddEditCategory.aspx?CategoryId=' + ID, '', sizestring);
}
------------------------------------------------------------------------------------------
2)Date validation using javascript
a) When we have two dates itself

function ValidateEndDate() {
if (document.getElementById('<%=wdcStartDate.ClientID %>').value != "" && document.getElementById('<%=wdcEndDate.ClientID %>').value != "") {
var StartDate;
var EndDate;
var value = document.getElementById('<%=wdcStartDate.ClientID %>').value;
var year = value.substring(0, value.indexOf("-"));
value = value.substring(value.indexOf("-") + 1);
var smonth = value.substring(0, value.indexOf("-"));
var dt = value.substring(value.indexOf("-") + 1);
StartDate = Date.UTC(year, smonth, dt, 0, 0, 0);
value = document.getElementById('<%=wdcEndDate.ClientID %>').value;
year = value.substring(0, value.indexOf("-"));
value = value.substring(value.indexOf("-") + 1);
smonth = value.substring(0, value.indexOf("-"));
dt = value.substring(value.indexOf("-") + 1);
EndDate = Date.UTC(year, smonth, dt, 0, 0, 0);
if (EndDate < StartDate) {
alert('End Date cannot be before Start Date');
return false;
}
}

return true;
}

b) When we have two dates in string format and check it as dates

<script language="javascript" type="text/javascript">
Date.prototype.toDDMMYYYYString = function ()
{
return isNaN (this) ? 'NaN' : [this.getDate() > 9 ? this.getDate() : '0' + this.getDate(), this.getMonth() > 8 ? this.getMonth() + 1 : '0' + (this.getMonth() + 1), this.getFullYear()].join('/')
}
Date.fromDDMMYYYY = function (s)
{
return (/^(\d\d?)\D(\d\d?)\D(\d{4})$/).test(s) ? new Date(RegExp.$3, RegExp.$2 - 1, RegExp.$1) : new Date (s)
}
function CheckToDate()
{
var FromDate = document.getElementById('<%=hfFromDate.ClientID %>').value;
var ToDate = document.getElementById('<%=hfToDate.ClientID %>').value;
var From = Date.fromDDMMYYYY(FromDate);
var To = Date.fromDDMMYYYY(ToDate);
if(From>To)
{
alert("To Date must be greater than From Date");
return false;
}
}
-----------------------------------------------------------------------------
3) To fire validation summary before showing an alert (Page_ClientValidate())

function ValidateSpecificValidationGroup() {
if (Page_ClientValidate(‘ValidationGroup1′)) {
return confirm(“Are you sure to modify above details?”);
}
}
------------------------------------------------------------------------------
4)Javascript to detect browser and screen height to set height of a div

<script type="text/javascript">
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ''+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;

// In Opera, the true version is after "Opera" or after "Version"
if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In MSIE, the true version is after "MSIE" in userAgent
else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);
}
// In Chrome, the true version is after "Chrome"
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
// In Safari, the true version is after "Safari" or after "Version"
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
// In most other browsers, "name/version" is at the end of userAgent
else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) )
{
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);
if (browserName.toLowerCase()==browserName.toUpperCase()) {
browserName = navigator.appName;
}
}
// trim the fullVersion string at semicolon/space if present
if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

majorVersion = parseInt(''+fullVersion,10);
if (isNaN(majorVersion)) {
fullVersion = ''+parseFloat(navigator.appVersion);
majorVersion = parseInt(navigator.appVersion,10);
}

if(screen.height!=null)
{
var setHeight;
if(browserName=="Microsoft Internet Explorer")
setHeight = screen.height-260+'px';
else if(browserName=="Firefox")
setHeight = screen.height-240+'px';
else if(browserName=="Chrome")
setHeight = screen.height-160+'px';
else if(browserName=="Opera")
setHeight = screen.height-170+'px';
else
setHeight = screen.height-260+'px';
document.getElementById('<%=divGV.ClientID %>').style.height=setHeight;
}
</script>
----------------------------------------------------------------------------------------
5)Check whether a textbox value is null or ""
document.getElementById('<%=txtName.ClientID%>').value.replace(/\s/g,"") == "";

------------------------------------------------------------------------------------------
6) Export contents in a gridview in excel format
In .aspx page,

<asp:LinkButton ID="lbtnExcelExport" runat="server" Text="Export To Excel" OnClick="lbtnExporttoExcel_Click"
class="linkButton" ToolTip="Click here to export the records to excel document"
Style="font-weight: bold; font-size: 13px; text-decoration: underline; cursor: hand;" />


In .aspx.cs page,

protected void lbtnExporttoExcel_Click(object sender, EventArgs e)
{
gvNonPaidLICReport.AllowPaging = false;
FillEmployees();
ArrayList arr = new ArrayList();
arr.Add("MyHiddenFieldName");
ExportGridView(gvNonPaidLICReport, "Non-Paid LIC Report", arr);
gvNonPaidLICReport.AllowPaging = true;
FillEmployees();
}


protected void ExportGridView(GridView grdView, string filename, ArrayList excludedColumnList)
{
// Clear response content & headers
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
// Add header
Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".xls");

Response.Charset = string.Empty;
Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
Response.ContentType = "application/vnd.xls";
// Create stringWriter
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
// Create HtmlTextWriter
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

// Remove controls from Column Headers
if (grdView.HeaderRow != null && grdView.HeaderRow.Cells != null)
{
for (int ct = 0; ct < grdView.HeaderRow.Cells.Count; ct++)
{
// Save initial text if found
string headerText = grdView.HeaderRow.Cells[ct].Text;

// Check for controls in header
if (grdView.HeaderRow.Cells[ct].HasControls())
{
// Check for link button
if (grdView.HeaderRow.Cells[ct].Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
// link button found, get text
headerText = ((LinkButton)grdView.HeaderRow.Cells[ct].Controls[0]).Text;
}
// Remove controls from header
grdView.HeaderRow.Cells[ct].Controls.Clear();
}
// Reassign header text
grdView.HeaderRow.Cells[ct].Text = headerText;
}
}
// Remove footer
if (grdView.FooterRow != null)
{
grdView.FooterRow.Visible = false;
}
// Remove unwanted columns (header text listed in removeColumnList arraylist)
foreach (DataControlField field in grdView.Columns)
{
if (excludedColumnList.Contains(field.HeaderText))
{
field.Visible = false;
}
}
// Call gridview's renderControl
grdView.RenderControl(htmlWrite);
// Write Response to browser
Response.Write(stringWrite.ToString());
Response.End();
}

------------------------------------------------------------------------------------------
7) To retrieve selected value and text of a dropdownlist using javascript
var keyValue =document.getElementById('<%=ddlProcessName.ClientID %>').options[document.getElementById('<%=ddlProcessName.ClientID%>').selectedIndex].value;


var keyValue =document.getElementById('<%=ddlOperators.ClientID %>').options[document.getElementById('<%=ddlOperators.ClientID%>').selectedIndex].text;

------------------------------------------------------------------------------------------
8) To allow only integer values in an asp textbox
<asp:TextBox ID="txtEmpID" runat="server" Width="150px" onChange="intonly(this);"
onkeyUp="intonly(this);" onkeyPress="intonly(this);"></asp:TextBox>

<script language="javascript" type="text/javascript">
function intonly(i)
{
if(i.value.length>0)
{
i.value=i.value.replace(/[^\d]+/g,'');
}
}
</script>
------------------------------------------------------------------------------------------
9) To restrict drop and count characters on 'copy paste' in a textbox
In .aspx page,
function CheckCount(source,maxLimit)
{
var length = document.getElementById(source).value.length;
if(length <= maxLimit-1)
{
return true;
}
else
{
return false;
}
}
function pasteHandler(source,maxLimit,destination)
{
var len= document.getElementById(source).value.length;
var currentData = clipboardData.getData("Text");
var total= parseInt(len) + parseInt(currentData.length);
var stringVal = document.getElementById(source).value + currentData;
if(total > maxLimit)
{
alert('You can enter only 1000 characters.');
}
else
{
insert(document.getElementById(source),currentData);
}
return false;
}
function insert(el, ins)
{
if (el.setSelectionRange)
{
el.value = el.value.substring(0, el.selectionStart) + ins + el.value.substring(el.selectionStart, el.selectionEnd) + el.value.substring(el.selectionEnd, el.value.length);
}
else if (document.selection && document.selection.createRange)
{
el.focus();
var range = document.selection.createRange();
range.text = ins + range.text;
}
}

In .aspx.cs page,

txtDescription.Attributes.Add("ondrop", "return false;");

txtDescription.Attributes.Add("onpaste", "return pasteHandler('" + txtDescription.ClientID + "','" + txtDescription.MaxLength + "');");
txtDescription.Attributes.Add("onkeypress", "return CheckCount('" + txtDescription.ClientID + "','" + txtDescription.MaxLength + "');");

-----------------------------------------------------------------------------------------
10)Encrypt and Decrypt

a) Using Secure Hash Algorithm (Encrypt Only)
public static string HashCode(string str)
{
string rethash = "";
try
{
System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
byte[] combined = encoder.GetBytes(str);
hash.ComputeHash(combined);
rethash = Convert.ToBase64String(hash.Hash);
}
catch (Exception ex)
{
string strerr = "Error in HashCode : " + ex.Message;
}
return rethash;
}

b)Add a class (say Cryptography.cs) and include below code
public static string Encrypt(string plainText)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText)); ;
}
public static string Decrypt(string cipherText)
{
return (SHA) Encoding.UTF8.GetString(Convert.FromBase64String(cipherText));
}
------------------------------------------------------------------------------------------
11)Without 3 tier architecture
In web.config,
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=10.11.16.32;Initial Catalog=DBName;User ID=sa;Password=sasa" />
</connectionStrings>

In .aspx.cs page,
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("ProcedureName", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@DocID", hfID.Value));
cmd.Parameters.Add(new SqlParameter("@AppDate", txt1.Text));
intTokenNo = (Int32)cmd.ExecuteScalar();
}

------------------------------------------------------------------------------------------

modified on Monday, September 5, 2011 3:31 AM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.