Wednesday, May 25, 2011

Selecting checkboxlist type on checkbox checked on OnAutoPostback=true

On pageload
-------------------
$(document).ready(




}

{
function () {var "input[id*='chkSelectAll']");if ("checked")) {"input[id*='chlTypeList']")."checked", "checked");"input[id*='chlTypeList']")."disabled", true);else //$("input[id*='chlTypeList']").removeAttr("checked");
}
});

SelectAll Checkbox
---------------------------




}



}
}
"input[id*='chlTypeList']")."disabled", false);function if ("checked")) {"input[id*='chlTypeList']")."checked", "checked");"input[id*='chlTypeList']")."disabled", true);else {"input[id*='chlTypeList']")."checked");"input[id*='chlTypeList']")."disabled", false);attr($(removeAttr($(attr($(attr($($(Check).attr(ChangeCheckboxlist(Check) {attr(
$(
attr(
$(
attr(
$(
$(Check).attr(
Check = $(

Friday, May 20, 2011

Limiting the No. of Characters in TextBox using JQuery

1. In aspx page:
<div>
<div>
<asp:ImageButton ID="imgAddCommentUser" CommandName="AddReply" runat="server" />
<asp:TextBox ID="txtReplies" runat="server" TextMode="MultiLine" onKeyUp="textCounter(this.id);"Text="Write a replies..."></asp:TextBox>
</div>
<div class="clear">
</div>
<div style="float: right; padding: 0 0 0 50px; *margin-top: -15px;"><span id="spanLeftChar" runat="server">
<small>4000 characters left</small>
</span>

In Jquery.js
---------------
eg: 4000 characters


 
        var spanObj = $(txtId).parent().next().next().children("span:first");       

        len = $(txtId).val().length;
        
        if (len > limit)
            $(txtId).val($(txtId).val().substring(0, limit));


      if((limit - len)>=0)
          $(spanObj).html("<small>" + (limit - len) + " characters left </small>")
        else
            $(spanObj).html("<small>0 characters left </small>")
    }

    function textCounter(txtId)
     {            
        var limit = 4000;
        var txtId = "#" + txtId;

The Other Side of FileUpload Control.

1. The maximum size of the fileupload control 2GB for .net 2.0 and 1GB for .net 1.0.

2  The default maximum size of the fileupload control is 4MB.

3. How to do error handling if the file size exceeds 10 MB or N MB. The steps are as follows

3.1 Create the Global.asax file which should be in the root directory of your application.

3.2 Place the below code in the Application_AuthenticateRequest event
 
(HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");//Approx 100 Kb(for page content) size has been deducted because the maxRequestLength proprty is the page size, not only the file upload size
int maxRequestLength = (runTime.MaxRequestLength - 100) * 1024;//This code is used to check the request length of the page and if the request length is greater than //MaxRequestLength then retrun to the same page with extra query string value action=exception

{


(HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));// Check if body contains data
{
if (workerRequest.HasEntityBody())// get the total body length
int requestLength = workerRequest.GetTotalEntityBodyLength();// Get the initial bytes loaded

initialBytes

{
int initialBytes = 0;if (workerRequest.GetPreloadedEntityBody() != null)= workerRequest.GetPreloadedEntityBody().Length;if (!workerRequest.IsEntireEntityBodyIsPreloaded())byte[] buffer = new byte[512000];// Set the received bytes to initial bytes before start reading

{
int receivedBytes = initialBytes;while (requestLength - receivedBytes >= initialBytes)// Read another set of bytesinitialBytes = workerRequest.ReadEntityBody(buffer, buffer.Length);// Update the received bytesreceivedBytes
}

}
}
}

3.3  In the Application_Error add the following code

HttpContext context = HttpContext.Current;
Exception ex = Context.Server.GetLastError();
if(ex != null)
if (ex.InnerException.Message.ToString().ToLower().IndexOf("request length exceed") >= 0)
{
context.Server.ClearError();
context.Response.Redirect(Resources.Redirection.FileMaximumUploadError);
}

3.4. In the web.config add the following

<httpRuntime requestValidationMode="2.0" maxRequestLength="10240" executionTimeout="600" />

maxRequestLength in kilobytes =eg. 10 Mb

3.5. In the FileMaximumUploadError.aspx add the error Message.

Thursday, May 12, 2011

Input $1500.00 Output 1500.00

object objData = dr["POExtendedCost"];
string strData = decimal.Parse(objData.ToString(), NumberStyles.Currency).ToString();