Thursday, January 26, 2012

How to write html/javascript code in blogger blog post?

How to write html/javascript code in blogger blog post? write html/javascript code in blogger blog postIf you have ever tried writing HTML/Javascript code in your blogger blog post then you might have found that it does not appear as code in the post. Instead the code is interpreted and displayed. The above problem can be simply fixed by replacing < with "Ampersand(&)lt;" and > by "Ampersand(&)gt;" . Here we are providing a few elegant ways to do this. We will start with the toughest one first. If you like easy things just skip to the last step.



Method 1 Open notepad and paste your code in it. Hit ctrl+h or choose Edit > Replace In Find what: box type < and in Replace with: box type "Ampersand(&)lt;" and hit Replace all button Similarly for > type > in Find what: box and "Ampersand(&)gt;" in Replace with: box. Your are done, the code is ready to be used in your post.



Method 2 Paste your code in the text box below and hit Convert button. Done! Your code is ready to be pasted in your blogger blog post. For easy access we suggest that you bookmark (ctrl+d) this page.



Method 3 The above method requires you to visit this page whenever you want to convert your code. This is waste of time and will also require your to have an active internet connection. Let's make things a bit easier download html converter now.



Method 4 The next method is the official solution from blogger. If you need to write html code in your post just select post options and in compose settings choose Show HTML literally. Any code now written will not be interpreted as HTML.

follow following link: http://bloggerfunda.blogspot.com/2009/11/how-to-write-htmljavascript-code-in.html

Wednesday, January 25, 2012

Grideview DataKeys in Asp.net Using C# code

GrideviewName.DataKeyNames = new string[] { "pid", "catId" };
OR

mension datakeys in the source code like in the Gridtag
asp:gridview DataKeyNames=pid,catId
In the above we are given datakeys names pid,catId

Get Datakeys values(pid,catId):

GridviewName.DataKeys[e.RowIndex].Values["Pid"]);
GridviewName.DataKeys[e.RowIndex].Values["catId"]);

Grid view Row Updation using Onblur event of TextBox in Javascript

Note:if you want Update gridview row when you changing the text in the textbox and you click on the out gridview or on the grideview
you can written Onblur event of textbox.
Ex:I update Quantity in the textbox by click on the webpage or gridview.
I written Onblur() event in the textbox as follows.this will call server side code

function changeQuantity(obj) {
if (obj.value == 0)
obj.value = 1;
document.getElementById('<%= ButtonName.ClientID %>').click();

server side Code:
protected void btnCheck_OnClick(object sender, EventArgs e)
{
foreach (GridViewRow item in GVCart.Rows)
{
string lPid = Convert.ToString(GVCart.DataKeys[item.RowIndex].Values["pid"]);
TextBox lQty = (TextBox)item.FindControl("txtQty");
}

}

TextBox event Onblur Is:
onblur="changeQuantity(this)"

Enter numbers only in TextBox using javascript code

function onlynumbers(event) {
if (event.keyCode == 46 || event.keyCode == 8) {
return true;
}
else {
// Ensure that it is a number and stop the keypress
if ((event.keyCode < 48 || event.keyCode > 57)) {
alert('enter only numbers....');
return false;
}
else {
return true;
}
}
this function can be written the the TextBox keypress event like

onkeypress="return onlynumbers(event)"

Monday, January 23, 2012

Email validation using Java Script

function validate()
{
var emailformat = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ //regular expression defining a 8 digit number
var email = document.getElementById('<%=txtEmail.ClientID %>').value;
if (email == "") {
alert('Enter emailid...');
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
if (email.search(emailformat) == -1) { //if match failed
alert("please enter valid emailid...");
return false;
document.getElementById('<%=txtEmail.ClientID %>').focus();
}
}
Call this function in OnClientClick of Button like

OnClientClick="javascript:return validate();"

Wednesday, January 4, 2012

Clear/Remove QueryString value in asp.net

In general query string not clear using following
Request.QueryString.Remove("id");
Request.QueryString.Clear();
you get error like Collection readolny

but we can solve this following code

PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("id");