29 September 2008

Update UpdatePanel Using Javascript

var prm=Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('ButtonName','');
or
prm._doPostBack('UpdatePanelName','');

Focus Back to that control -C#

ScriptManager sm = ScriptManager.GetCurrent(this);
sm.SetFocus(TextBox2);

Allow only numeric values in textbox-Javascript

function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 &&
(charCode < 48
Or
charCode > 57) )

return false;
return true;
}

----------------------------------------------
onkeypress="return isNumberKey(event);"

To Find No Of Days in a month -SQL

DECLARE @date datetime
set @date='1/1/2008'
DECLARE @dayCount int
--To Find No Of Days in a month
SET @dayCount=Day(DateAdd(Month, 1, @date) - Day(DateAdd(Month, 1, @date)))
print @daycount

Date Conversion

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-GB");

String requestTempDate = (Convert.ToDateTime(txtRequestDate.Text, culture)).ToShortDateString();

DateTime requestDate = Convert.ToDateTime(DateTime.Now, culture);
---------------------------------------------------------------

txtRequestDate.Text = DateTime.Now.ToString("dd MMM yyyy");


DateTime Date = Convert.ToDateTime(DateTime.Now.ToShortDateString());

GridView-Row Identification In TemplateField ( TextBox )

//Getting gridview row in textchange of template field
protected void txtGrnQuantity_TextChanged(object sender, EventArgs e)
{
TextBox txtGrnQuantity = (TextBox)grvGRN.Rows[((GridViewRow)((TextBox)sender).Parent.Parent).RowIndex].FindControl("txtGrnQuantity");
TextBox txtRejectedQuantity = (TextBox)grvGRN.Rows[((GridViewRow)((TextBox)sender).Parent.Parent).RowIndex].FindControl("txtRejectedQuantity");
}