Vinit Patel

Archive for the ‘Javascript’ Category

Hi,

If I want to select only limited(2) items from the listbox then using Jquery use the below code,

<head id=”Head1″ >
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”></script&gt;

</head>
<body>
<form runat=”server”>
<asp:ListBox ID=”ListBox1″ runat=”server” SelectionMode=”Multiple”>
<asp:ListItem Text=”Item1″></asp:ListItem>
<asp:ListItem Text=”Item2″></asp:ListItem>
<asp:ListItem Text=”Item3″></asp:ListItem>
<asp:ListItem Text=”Item4″></asp:ListItem>
</asp:ListBox>
</form>
</body>
<script type=”text/javascript”>
$(‘#<%= ListBox1.ClientID %>’).change(function()
{
if ($(this).find(‘option:selected’).length > 2)
{
this.options[this.selectedIndex].selected = false;
}
;
});
</script>

</html>

Using Javascript

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head id=”Head1″ >

<script type=”text/javascript”>
function test()
{
var selectedCount = 0;
var listBox = document.getElementById(‘<%= ListBox1.ClientID %>’);
var i = 0;
do
{
if (listBox.options[i].selected)
{
selectedCount++;
if (selectedCount > 2)
{
listBox.options[i].selected = false;
break;
}
}
i++;

} while (i < listBox.options.length)
}
</script>

</head>
<body>
<form runat=”server”>
<asp:ListBox ID=”ListBox1″ runat=”server” onchange=”test()” SelectionMode=”Multiple”>
<asp:ListItem Text=”Item1″></asp:ListItem>
<asp:ListItem Text=”Item2″></asp:ListItem>
<asp:ListItem Text=”Item3″></asp:ListItem>
<asp:ListItem Text=”Item4″></asp:ListItem>
</asp:ListBox>
</form>
</body>
</html>

Advertisements

There is two ways which i know,

First :=

ClientScript.RegisterStartupScript(GetType(), “ShowContinue”, “ShowContinue();”, true);

second :=

Public m_sScript As String = “”
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
m_sScript = “<script type=””text/javascript””>ShowContinue()</script>”
End Sub

and put <%=m_sScript%> at the end of the aspx page

Basically we have the last Textbox for any web page.

Then we dont want to move the cursor position to the button,

this will work only with Internet Explorer…

Last we have the cursor control in the password textbox.

From there only if we want to Login to the next page .

For Ex, Like Below

We have to write below code,

In the page load event,

txtPassword.Attributes.Add(“onkeydown”, “if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById(‘” + btnSubmit.UniqueID + “‘).click();return false;}} else {return true}; “);

Vinit Patel.


Advertisements

Calendar

February 2018
M T W T F S S
« Jan    
 1234
567891011
12131415161718
19202122232425
262728  

Stats Of Blog

  • 7,290 hits

Cluster Map