Archive for the ‘.Net’ Category

h1

requiredfieldvalidator not working onclientclick

May 24, 2016

 

Requiredfieldvalidator not working onclientclick added in button.

Code  : This code will not execute required field validator

 <asp:Button ID="btnSubmit" runat="server" Text="Check" 
OnClick="btnSubmit_Click" 
OnClientClick="javascript:return confirm('Are you sure to Submit?')"
 ValidationGroup="Submit" />

use Page_ClientValidate() predefined function to avoid issue.

Solution :

 <asp:Button ID="btnSubmit" runat="server" Text="Check" 
OnClick="btnSubmit_Click" 
OnClientClick="return CheckToProceed();"
 ValidationGroup="Submit" />

Javascript ::

function CheckToProceed() {
 if (Page_ClientValidate()) {
return confirm('Are you sure to Submit?')
}
}

Reference : stackoverflow

Advertisements
h1

Set Document mode standard/Edge in IE

September 2, 2015

set Document mode standard/Edge in IE
Code :

Add meta tag in web page
<meta http-equiv=”X-UA-Compatible” content=”IE=edge” />

If you are using .net you can add this to the web.config

<system.webServer>
    <httpProtocol>
     <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>
h1

Remove invalid characters from file name and path

February 4, 2015

Code :

string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());

foreach (char c in invalid)
{
strFileName = strFileName.Replace(c.ToString(), “”);
}

h1

ignore case in replace C#

July 3, 2014

we can ingnore case in replacing test using Regex

to use Regex include System.Text.RegularExpressions header file

Coding :

Regex.Replace(string,TextToRemove,string.Empty,RegexOptions.IgnoreCase);

h1

Convert Date to any format from any other format

June 30, 2012

Convert a one date format to any other date format.
Date format must not be a regular Date format like ‘MM/dd/yyyy’. it can be a any format like ‘yyyyMMdd’

Coding :

public string DateFormatter(string Date,string RevFormat,string ReqFormat)
{
DateTime MyDateConverted = DateTime.ParseExact(Date, RevFormat, System.Globalization.CultureInfo.InvariantCulture);
string ReqDate = MyDateConverted.ToString(@ReqFormat);
return ReqDate;
}
h1

Numeric only text box in .net Winforms

July 18, 2011

We can create Numeric only text boxes in .Net Windows forms application with adding below code in Key Press Event.

Numeric only text boxes

private void txtBox_KeyPress(object sender, KeyPressEventArgs e)

{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != ‘.’)
{
e.Handled = true;
}

// only allow one decimal point
if (e.KeyChar == ‘.’ && (sender as TextBox).Text.IndexOf(‘.’) > -1)
{
e.Handled = true;
}
}

 

Integer only text boxes

private void txtBox_KeyPress(object sender, KeyPressEventArgs e)

{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) )
{
e.Handled = true;
}

}

h1

Confirm Dialog in .Net WinForms

April 26, 2011

We can use MessageBox as Confirm Dialog box

Coding

if(MessageBox.Show(“Confirm this?”, “Test”, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
/// Code for ‘Yes’
}
else
{
/// Code for ‘No’
}