Saturday, March 30, 2013

Limiting Textarea Text,

In asp.net max length is not working when text mode is set to multi line.
To achieve same functionality for text area , we can call same function two event
onkeyup =" return CheckMaxLenghtOfMessage(this,160)" onchange =" return CheckMaxLenghtOfMessage(this,160)"

OnKeyup will come in light when user typing text by keybord.
OnChange will come in light when user copy paste the text in values.

solution is that only trim the extra value.


  function CheckMaxLenghtOfMessage(sender, maxlimit) {
     
if (sender.value.length >= maxlimit) {

sender.value = sender.value.substring(0, maxlimit);

}
   }
     <asp:TextBox ID="test" runat="server" onkeyup =" return CheckMaxLenghtOfMessage(this,10)" onchange =" return CheckMaxLenghtOfMessage(this,160)" TextMode="MultiLine"></asp:TextBox>

Thanks
Mahesh k Sharma

Wednesday, March 20, 2013

JavaScriptSerializer DateTime Problem

  JavaScriptSerializer  class Deserialize Method does not return same date time wich is is not returning the value which is Serializing by Serialize Method define in JavaScriptSerializer. At least for me it is bug. :) System.Web.Script.Serialization.



public class SimpleClassWithJavaScriptSerializerError {


private DateTime m_Date;


public DateTime Date {


get { return m_Date; }


set { m_Date = value; }//Code which is giving error.

}

}


public class SimpleClassFixForAjax {


private DateTime m_Date;


public DateTime Date {


get { return m_Date; }


set { m_Date = DateTime.SpecifyKind(value, DateTimeKind.Utc); }//This way can fix the problem

}

}


protected void Page_Load(object sender, EventArgs e) {

System.Web.Script.Serialization.
JavaScriptSerializer javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();


DateTime dt = DateTime.Now;


SimpleClassWithJavaScriptSerializerError simpleClassWithJavaScriptSerializerError = new SimpleClassWithJavaScriptSerializerError();

simpleClassWithJavaScriptSerializerError.Date = dt;

Response.Write(

"<br/><br/>This is error from JavaScriptSerializer becase deserilaization is not returning which is value which is serialized.");

Response.Write(
string.Format("<br/> Before serialization: {0}", simpleClassWithJavaScriptSerializerError.Date));


string jsonStr = javaScriptSerializer.Serialize(simpleClassWithJavaScriptSerializerError);


SimpleClassWithJavaScriptSerializerError newInstance = javaScriptSerializer.Deserialize<SimpleClassWithJavaScriptSerializerError>(jsonStr);

Response.Write(
string.Format("<br/> After serialization: {0}",newInstance.Date));


//How to fix

Response.Write(
"<br/>------------------------------------------------------------------------------------------------");

 


SimpleClassFixForAjax simpleClassFixForAjax = new SimpleClassFixForAjax();

simpleClassFixForAjax.Date = dt;

Response.Write(

string.Format("<br/> Before serialization: {0}", simpleClassFixForAjax.Date));

jsonStr = javaScriptSerializer.Serialize(simpleClassFixForAjax);


SimpleClassFixForAjax simpleClassFixForAjaxDes = javaScriptSerializer.Deserialize<SimpleClassFixForAjax>(jsonStr);

Response.Write(
string.Format("<br/> After serialization: {0}", simpleClassFixForAjaxDes.Date));


DateTime d = DateTime.SpecifyKind(new DateTime(), DateTimeKind.Utc);

}

Friday, March 15, 2013

Keyup and Keydown on the LI

When you press arrow key up or down your LI should be heighlighed according to movements of arrow key.
<style type="text/css">/*Add this in master page*/

.selectedMahesh

{

background: #ccc;

}

</style>

<script type="text/javascript">

 

function Test(e) {

var $listItems = $('[id=maheshUL] li');/*Use to get UL selector should be accroding to DOM*/



var key = e.keyCode,

$selected = $listItems.filter('.selectedMahesh'),

$current;

if (key != 40 && key != 38) return;

$listItems.removeClass('selectedMahesh');

if (key == 40) // Down key

{

if (!$selected.length || $selected.is(':last-child')) {

$current = $listItems.eq(0);

}

else {

$current = $selected.next();

}

}

else if (key == 38) // Up key

{

if (!$selected.length || $selected.is(':first-child')) {

$current = $listItems.last();

}

else {

$current = $selected.prev();

}

}

$current.addClass(
'selectedMahesh');/*Add the class which is used to heighligh the element*/

}

</script>

<input id="input_city" type="text" onkeydown="Test(event);" />

<div >

<ul id='maheshUL'>

<li >New York</li>

<li >London</li>

<li >Paris</li>

<li >Sydney</li>

</ul>

</div>

Friday, March 1, 2013

Temp filese of running ASP.NET project:


Temp filese of running project:

c:\Users\<username>AppData\Local\Temp\Temporary ASP.NET Files\

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

Thanks
Mahesh

How to get public token on assembly DLL



Step 1:
Open command tool of Visual studio
Step 2: take the path of assembly. say it is stored in d:\ with name of asm.
Step 3:
paste the folloing command:

C:\Program Files (x86)\Microsoft Visual Studio ??.? \VC>sn -T d:\asm.dll

Thanks
Mahesh Kumar Sharma