Monday, April 26, 2010

Capturing Enter Key Press in Text Box ASP.NET Web Application

Copy This Java Script:

function test(e) {
e = e || window.event;
alert(e.keyCode);
if (e.keyCode == "13") {

document.getElementById("Text1").value = "13";
}
}




-----------------------------------------------------------------------------

In .aspx Page Add Particular Text box within div tag and place hidden input .

< div onkeydown="test(event)" >

< asp:textbox autopostback="true" id="TextBox1" ontextchanged="TextBox1_TextChanged" runat="server" > </asp:textbox >
<input  id="Text1" runat="server" type="text" />
</div>
<asp:textbox id="TextBox2" runat="server"></asp:textbox>


Also add the ontextchanged event in Text Box.

------------------------------------------------------------------------------

In .ascx.cs Page Within the TextChanged Event add follows .

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if( Text1.Value=="13")
{
Text1.Value = "";
//ENTER YOUR CODE
TextBox2.Text = "Enter Key";

}
}

Tuesday, April 20, 2010

Set Active Tab in Ajax tab Panel When validate is fire

You can simplify this java script for doing this.

function SetActiveTab() {

if (typeof (Page_Validators) == "undefined") return false;

try {

var noOfValidators = Page_Validators.length;

for (var validatorIndex = 0; validatorIndex <>

var validator = Page_Validators[validatorIndex];

ValidatorValidate(validator);

if (!validator.isvalid) {

validator=document.getElementById(validator.id);

var parentTab=validator;

var parentTabNodeName=validator;

do {

parentTabNodeName=parentTab.parentNode.nodeName;

parentTab=parentTab.parentNode;

} while ((parentTabNodeName!='DIV')||($find(parentTab.id)==null)||($find(parentTab.id)=='')||(parentTab.className !='ajax__tab_panel'));

if((parentTab.className =='ajax__tab_panel')){

var tabPanel = $find(parentTab.id);

var tabContainer =tabPanel.get_owner();

tabContainer.set_activeTabIndex(tabPanel.get_tabIndex());

}

break;

}

}

return false;

}

catch (Error) {

}

}


Call button click (In asp button On client Click)