Thursday, October 9, 2008

using range validater its easy to validate the Only accept futuredate filed

//in your page load add following codes

rvDelivery.MinimumValue = DateTime.Now.ToShortDateString();
rvDelivery.MaximumValue = DateTime.MaxValue.ToShortDateString();

//Add a customer validator to the page and change this values only
controleto validate : your txtboxname
validation group: your validation group
type: Date

Navigate throught List box using C#

System.Text.StringBuilder sbVender = new System.Text.StringBuilder();

sbVender.Append("<VENDORS>");
foreach (ListItem item in lbVendors.Items)
{
if (item.Selected)
{
sbVender.AppendFormat("<VENDOR VendorId=\"{0}\" />", item.Value.ToString());
}
}
sbVender.Append("</VENDORS>");

Register Ajecx pro with webconfgig C#

//when closing selection group</sectionGroup>
<sectionGroup name="ajaxNet">
<section name="ajaxSettings" type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2" requirePermission="false" restartOnExternalChanges="true"/>
</sectionGroup>

//When nexto the

//</appSettings> Closing
<ajaxNet>
<ajaxSettings>
<urlNamespaceMappings useAssemblyQualifiedName="false" allowListOnly="false">
<!--
Set the attribute useAssemblyQualifiedName to true to enable
use of assemblies placed in the GAC by using the full assembly
qualified name.

To hide internal knowledge of assemblies, classes and namespace
you can override the name of the virtual http endpoints.

<add type="Namespace.Class1,Assembly" path="mypath" />
-->
</urlNamespaceMappings>
<jsonConverters>
<!--
This section can be used to add new IJavaScriptConverters to the
Ajax.NET Professional engine. If you want to disable built-in
converters you can use the remove tag.

<remove type="Namespace.Class1,Assembly"/>
<add type="Namespace.Class2,Assembly"/>

<add type="AjaxPro.BitmapConverter,AjaxPro.2" mimeType="image/jpeg" quality="100"/>
-->
</jsonConverters>
<!--
Set the enabled attribute to true to get Stack, TargetSize and Source
information if an exception has been thrown.
-->
<debug enabled="false"/>
<!--
This is the default configuration used with Ajax.NET Professional. You
can put there your static JavaScript files, or remove the path attribute
to completly disable the files.

<scriptReplacements>
<file name="prototype" path="~/ajaxpro/prototype.ashx" />
<file name="core" path="~/ajaxpro/core.ashx" />
<file name="converter" path="~/ajaxpro/converter.ashx" />
</scriptReplacements>
-->
<!-- <encryption cryptType="" keyType="" /> -->
<!--
Set the enabled attribute to true to enable the use of an Ajax.NET Professional
token. This will send a token to the client that will be used to identify if the
requests comes from the same PC.
-->
<token enabled="false" sitePassword="password"/>
<!--
The oldStyle section can be used to enable old styled JavaScript code or
functions that are not used any more.

<oldStyle>
<objectExtendPrototype/>
<appCodeQualifiedFullName/>
<allowNumberBooleanAsString/>
<sessionStateDefaultNone/>
<includeMsPrototype/>
<renderDateTimeAsString/>
<noUtcTime/>
</oldStyle>
-->
</ajaxSettings>
</ajaxNet>

<location path="ajaxpro">
<system.web>
<pages validateRequest="false"/>
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
<!--
If you need to have Ajax.NET Professional methods running on the
login page you may have to enable your own authorization configuration
here.
-->
<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".

-->
</system.web>
</location>

validate restict future days/back dates

function checkDate(s,e)
{
var strSplit = e.Value.split("/");
var month = eval(strSplit[0]);
var year = eval(strSplit[2]);
var date = eval(strSplit[1]);

var validDate= new Date(year,month-1,date);
var systemDate = new Date();

if ( systemDate > validDate)
{
e.IsValid = true;
}
else
{
e.IsValid = false;
}
}


//and then create

customer validato

change only this properties
clemt validation functionality=checkDate
controletovalidate=your txtbox name
display=dynamic
errormessage=your error message
change validation group acordingly (Recomended)

validate the onlynumber for text box like money (13245.55)dot allowed using java scripts

function isDecimalKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode

if(charCode==46)
{

return true;
}
else
{
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
}
return true;

}

//in the copd addthe follown=ing to the text box event

onkeypress="return isDecimalKey(event)"

using lnk button and Navigate to another URL

if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
LinkButton lnkbuttonPay = ((LinkButton)e.Row.Cells[2].FindControl("LinkButton1"));
if (lnkbuttonPay != null)
{
lnkbuttonPay.PostBackUrl = "../Vendor/PayVendorOutStanding.aspx?Vendorid=" + gvVender.DataKeys[e.Row.RowIndex].Values[0].ToString() + "&venderName=" + gvVender.DataKeys[e.Row.RowIndex].Values[1].ToString() + "&Outstanding=" + gvVender.DataKeys[e.Row.RowIndex].Values[2].ToString();

}
}
catch (Exception ex)
{
if (Master.CurrentUser != null)
SLStopException.WriteEventLogs(ex, Constants.Database_Connection_Name, string.Empty + "-Admin");
else
SLStopException.WriteEventLogs(ex, Constants.Database_Connection_Name, "Anonymous-Admin");
}
}

validation Using regular expression validation

^\d{1,5}(\.\d{1,2})?$
format should be
XXXX.XX

1-5 . and 1 to 2 digits

rawdatabound handlingand disabling link in datagrid acordingly

protected void gvOrderPhotoPrint_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkPhotoOrderDelete");
string Status = gvOrderPhotoPrint.DataKeys[e.Row.RowIndex]["ClientStatusDisplay"].ToString().Trim();
if (lnkDelete != null)
{
lnkDelete.Attributes.Add("onclick", "return ConfirmDelete();");
if (Status == "In Progress")
{
lnkDelete.Enabled = false;
}

}


}
}
catch (Exception ex)
{

}
}

histry object in java script history.forward

other methods

Method
back() Loads the previous URL in the history list
forward() Loads the next URL in the history list
go() Loads a specific page in the history list

java script validation for easy numeric only text field

//java script validation for easy numeric only text field
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;

}

//source code method calling area


valuble validation expresion for format $XXXX.XX

^\d{1,5}(\.\d{1,2})?$

format should be $XXXX.XX

Advance search using xml (SQL Query)

SELECT vwCarReservationsforVendorCost.VendorId, vwCarReservationsforVendorCost.VendorName, SUM(isnull (vwCarReservationsforVendorCost.VendorcostinRs,0)) AS Total,Sum (isnull(tblVendorPaymentVouchers.Amount,0)) AS AmountPaid, (SUM(isnull (vwCarReservationsforVendorCost.VendorcostinRs,0))-Sum (isnull(tblVendorPaymentVouchers.Amount,0))) AS Outstanding
FROM vwCarReservationsforVendorCost
LEFT OUTER JOIN tblVendorPaymentVouchers ON
tblVendorPaymentVouchers.VendorId=vwCarReservationsforVendorCost.VendorId
WHERE (ReservedDate >= @OrderDateFrom OR @OrderDateFrom = '01/01/1900') AND
(ReservedDate<=@OrderDateTo OR @OrderDateTo='01/01/1900') AND
(vwCarReservationsforVendorCost.vendorId in (SELECT VendorId FROM OPENXML (@iDoc, '/VENDORS/VENDOR',1) WITH (VendorId INT)) OR @Vendors='')
GROUP BY vwCarReservationsforVendorCost.VendorId,vwCarReservationsforVendorCost.VendorName



//this is how you enter the parameters from front end

foreach (ListItem item in lbDeliveryService.Items)
{
if (item.Selected)
{
sbVender.AppendFormat("", item.Value.ToString());
}
}
sbVender.Append("");


DataSet ds = OBJOrder.SearchVendorDeliverCostAnalysisReports(fromDate, toDate, sbVender.ToString());

Usefull String for mattings in C#

"No formatting: " + theDecNumber.ToString();
"Currency formatting: " + theDecNumber.ToString("C");
"Exponential formatting: " + theDecNumber.ToString("E");
"Fixed-point formatting: " + theDecNumber.ToString("F2");
"General formatting: " + theDecNumber.ToString("G");
"Number formatting to 2 decimal places: " + theDecNumber.ToString("N2");
"Number formatting to 3 decimal places: " + theDecNumber.ToString("N3");
"Number formatting to 4 decimal places: " + theDecNumber.ToString("N4");
"Percent formatting: " + theDecNumber.ToString("P0");

Go thoroug list box and get the values whic checked

foreach (ListItem item in lbVendors.Items)
{
if (item.Selected)
{
sbVender.AppendFormat("", item.Value.ToString());
}
}