I have 2 textboxs, 2 checkboxs and 2 labels.
first textbox, checkbox, and label related to each other and the same for the rest.
textbox should accept valid phone number based on jquery validation plugin and when the chackbox check the validation rule would change and in both option the error message would disply inside the label.
I have no problem to implement that for one text box but when I add second one will have a problem and only the validation will happen for the second one only.
please look at my code and advice.
<script src="js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
var RegularExpression;
var USAPhone = /^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/;
var InterPhone = /^\d{9,12}$/;
var errmsg;
function ValidPhoneHome(sender) {
if (sender.checked == true) {
RegularExpression = InterPhone;
errmsg = "Enter 9 to 12 numbers as international number";
}
else {
RegularExpression = USAPhone;
errmsg = "Enter a valid number";
}
jQuery.validator.addMethod("phonehome", function(value, element) {
return this.optional(element) || RegularExpression.test(value);
}, errmsg);
}
function ValidMobileHome(sender) {
if (sender.checked == true) {
RegularExpression = InterPhone;
errmsg = "Enter 9 to 12 numbers as international number";
}
else {
RegularExpression = USAPhone;
errmsg = "Enter a valid number";
}
jQuery.validator.addMethod("mobilephone", function(value, element) {
return this.optional(element) || RegularExpression.test(value);
}, errmsg);
}
$(document).ready(function() {
ValidPhoneHome("#<%= chkIntphoneHome%>");
ValidMobileHome("#<%= chkIntMobileHome%>");
$("#aspnetForm").validate({
rules: {
"<%=txtHomePhone.UniqueID %>": {
phonehome: true
}
}
, errorLabelContainer: "#lblHomePhone",
rules: {
"<%=txtMobileHome.UniqueID %>": {
mobilephone: true
}
}
, errorLabelContainer: "#lblMobileHome"
})
</script>
<asp:CheckBox ID="chkIntphoneHome" runat="server" Text="Internation Code" onclick="ValidPhoneHome(this)" >
<asp:TextBox ID="txtHomePhone" runat="server" ></asp:TextBox>
<label id="lblHomePhone"></label>
<asp:CheckBox ID="chkIntMobileHome" runat="server" Text="Internation Code" onclick="ValidMobileHome(this)" />
<asp:TextBox ID="txtMobileHome" runat="server"></asp:TextBox>
<label id="lblMobileHome"></label>
here is the correct code:
<script src="js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/js.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
ValidPhoneHome("#<%= chkIntphoneHome%>");
ValidMobileHome("#<%= chkIntMobileHome%>");
$("#aspnetForm").validate({
rules: {
"<%=txtHomePhone.UniqueID %>": {
phonehome: true
},
"<%=txtMobileHome.UniqueID %>": {
mobilephone: true
}
},
errorElement: "mydiv",
wrapper: "mydiv", // a wrapper around the error message
errorPlacement: function(error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top - (element.height() / 2));
}
});
});
</script>
<div id="mydiv">
<asp:CheckBox ID="chkIntphoneHome" runat="server" Text="Internation Code" Style="position: absolute;
top: 113px; left: 549px;" onclick="ValidPhoneHome(this)"
/>
<asp:TextBox ID="txtHomePhone" runat="server" Style="top: 147px; left: 543px; position: absolute;
height: 22px; width: 128px" ></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtHomePhone_FTBE" runat="server"
Enabled="True" FilterType="Numbers" TargetControlID="txtHomePhone">
</cc1:FilteredTextBoxExtender>
<label id="lblHomePhone"
style="position:absolute; top: 175px; left: 451px; width: 351px;"></label>
<asp:CheckBox ID="chkIntMobileHome" runat="server" Style="position: absolute; top: 200px;
left: 535px;" Text="Internation Code" onclick="ValidMobileHome(this)" />
<asp:TextBox ID="txtMobileHome" runat="server" Style="top: 231px; left: 555px; position: absolute;
height: 22px; width: 128px"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="txtMobileHome_FilteredTextBoxExtender"
runat="server" Enabled="True" FilterType="Numbers"
TargetControlID="txtMobileHome">
</cc1:FilteredTextBoxExtender>
<label id="lblMobileHome" style="top: 254px; left: 449px; position: absolute;
height: 17px; width: 345px"></label>
<asp:CheckBox ID="chkIntFaxHome" runat="server" Style="position: absolute; top: 274px;
left: 567px;" Text="Internation Code" onclick="ValidFaxHome(this)"
/>
<asp:TextBox ID="txtFaxHome" runat="server" Style="top: 294px; left: 569px; position: absolute;
height: 22px; width: 128px"></asp:TextBox>
<label id="lblFaxHome" style="top: 321px; left: 483px; position: absolute;
height: 22px; width: 294px"></label>
<cc1:FilteredTextBoxExtender ID="txtFaxHome_FilteredTextBoxExtender"
runat="server" Enabled="True" FilterType="Numbers" TargetControlID="txtFaxHome">
</cc1:FilteredTextBoxExtender>
</div>
Related
This is my ASP.NET page :
<div id="dvtgl1" style="display: none">1.
<asp:TextBox ID="TxtTglCuti1" runat="server" MaxLength="1" style="width: 140px; height: 35px; padding: 12px 10px; box-sizing: border-box; border: 1px solid Silver; border-radius: 4px;" ValidationGroup="MKE"></asp:TextBox><br /><br /></div>
<div id="dvtgl2" style="display: none">2.
<asp:TextBox ID="TxtTglCuti2" runat="server" MaxLength="1" style="width: 140px; height: 35px; padding: 12px 10px; box-sizing: border-box; border: 1px solid Silver; border-radius: 4px; " ValidationGroup="MKE"></asp:TextBox><br /><br /></div>
This is my jQuery script :
$(function(){
$("#<%= TxtTglCuti1.ClientID %>").datepicker({
//dateFormat: 'dd/mm/yy',
numberOfMonths: 1,
showButtonPanel: true,
minDate: dateToday,
beforeShowDay: DisableMonday
});
$("#<%= TxtTglCuti2.ClientID %>").datepicker({
// dateFormat: 'dd/mm/yy',
numberOfMonths: 1,
showButtonPanel: true,
minDate: dateToday, beforeShowDay: DisableMonday
});
This is my VB.NET class :
If (TxtTglCuti1.Text = "") And (TxtTglCuti2.Text = "") And (TxtTglCuti3.Text = "") And (TxtTglCuti4.Text = "") And (TxtTglCuti5.Text = "") And (TxtTglCuti6.Text = "") And (TxtTglCuti7.Text = "") And (TxtTglCuti8.Text = "") And (TxtTglCuti9.Text = "") And (TxtTglCuti10.Text = "") And (TxtTglCuti11.Text = "") And (TxtTglCuti12.Text = "") Then
Response.Write("<script>alert('Data tidak boleh kosong')</script>")
Instead of building a block of code to check every TextBox that contains the date value from DateTimePicker and jQuery of all the text boxes.I built it to assign the value to an array like this :
txt_tgl_cuti(0) = TxtTglCuti1.Text
txt_tgl_cuti(1) = TxtTglCuti2.Text
The thing is, it only works for a small record.
How should I check it dynamically ? I have 12 record of text boxes and my goal is to build a function to prevent users to input duplicate date values in the TextBox
Below are the simle way you can check all text box values are blank,
.ASPX
<asp:PlaceHolder ID="plhDates" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</asp:PlaceHolder>
<asp:Button ID="btnSubmit" Text="text" runat="server" OnClick="btnSubmit_Click" />
.VB
Protected Function MySub() As Boolean
For Each ctl As Control In plhDates.Controls
If TypeOf ctl Is TextBox Then
If (CType(ctl, TextBox).Text = "") Then
Return True
End If
End If
Next
Return False
End Function
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs)
Dim isContainBlankValue As Boolean = MySub() //return true if any of the textbox have blank value
End Sub
#(Html.Kendo().Upload()
.Name("files").Multiple(false)
.HtmlAttributes(new { #style = "width:100%" })
.HtmlAttributes(new { accept = ".doc, .docx, .pdf, .ppt, .pptx " }) )
<input type="button" id="btnsubmit" value="Save"/>
<script id="fileTemplate" type="text/x-kendo-template">
<div class='file-wrapper'>
<label class="col-sm-1 col-xs-1" style="padding-left:0px!important;">
<span class='file-icon #=addExtensionClass(files[0].extension)#'></span>
</label>
<label class="col-sm-9 col-xs-9"><span class='uploadFileName'>#=name#</span></label>
<label class="col-sm-9 col-xs-9" style="margin-top:20px;display:none;">
<input type="text" class="k-textbox"
data-val-required="*"
style="width:70%"
id="txtFileName" name="txtFileName"
value="#=name.substring(0, name.lastIndexOf('.'))#" />
<span class="k-icon k-i-tick fileRenameTick" style="cursor:pointer;" data-extension="#=name.split('.').pop()#"></span>
<span class="k-icon k-i-close fileRenameTickClose" style="cursor:pointer;"></span>
</label>
<div class="col-sm-1 col-xs-1 btnFileRemove" style="padding-right:0px!important;padding-left:0px!important;margin-left:0px!important;width:5%!important;border:0px solid red;">
<span class='k-icon k-i-close fileRemove'></span>
</div>
</div>
</script>
<script>
var myfile = [];
$(document).ready(function () {
});
var i = 0;
function onUpload(e) {
myfile.push(e.files[0]);
}
$('#btnsubmit').click(function () {
var fileRenameList = [];
var formData = new FormData();
formData.append("BookBackImage", $("#companyname").val());
formData.append("BookFrontImage", $("#country").val());
for (var i = 0; i < myfile.length; i++) {
alert(myfile.length);
formData.append("file[" + i + "]", myfile[i].rawFile);
}
$('.uploadFileName').each(function () {
fileRenameList.push($(this).text());
});
formData.append("FrontImageRename", JSON.stringify(fileRenameList));
$.ajax({
type: "POST",
url: '#Url.Action("Index","Library")',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
},
error: function (error) {
}
});
});
function addExtensionClass(extension) {
switch (extension) {
case '.jpg':
case '.jpeg':
case '.img':
case '.gif':
return "img-file";
case '.png':
return "png-file";
case '.doc':
case '.docx':
return "doc-file";
case '.ppt':
case '.pptx':
return "ppt-file";
case '.xls':
case '.xlsx':
return "xls-file";
case '.pdf':
return "pdf-file";
case '.zip':
case '.rar':
return "zip-file";
default:
return "default-file";
}
}
$(document).on("click", ".fileRenameTick", function (e) {
e.preventDefault();
var inputval = $(this).siblings('input').kendoValidator().data("kendoValidator");
if (inputval.validate()) {
var ext = $(this).data("extension");
var reName = $(this).siblings('input').val() + "." + ext;
$(this).parent('label').prev('label').children('span').text(reName);
$(this).parent('label').css("display", "none");
$(this).parent('label').prev('label').css("display", "inline");
}
});
$(document).on("click", ".fileRenameTickClose", function (e) {
e.preventDefault();
$(this).parent('label').css("display", "none");
$(this).parent('label').prev('label').css("display", "inline");
});
$(document).on("click", ".fileRemove", function (e) {
e.preventDefault();
$(this).parent('div').parent('div').parent('li').remove();
var uid = $(this).parent('div').parent('div').parent('li').data("uid");
$.each(myfile, function (i, el) {
if (this.uid === uid) {
myfile.splice(i, 1);
}
});
});
$(document).on("click", ".uploadFileName", function (e) {
e.preventDefault();
var str = $(this).text();
var rest = str.substring(0, str.lastIndexOf("."));
$(this).parent('label').next('label').css("display", "inline");
$(this).parent('label').next('label').children('input').val(rest);
$(this).parent('label').css("display", "none");
$(this).parent('label').next('label').children('.field-validation-error').hide();
$("#txtFileName_validationMessage").hide();
});
</script>
<style>
.file-icon {
display: inline-block;
float: left;
width: 48px;
height: 48px;
margin-top: 13.5px;
}
.lblForMaterialName .file-icon {
float: left;
width: 20px;
height: 20px;
}
.img-file {
background-image: url(../content/web/upload/jpg.png);
}
.png-file {
background-image: url(../content/web/upload/png_converted.png);
}
.doc-file {
background-image: url(../content/web/upload/doc.png);
}
.ppt-file {
background-image: url(../content/web/upload/ppt.png);
}
.pdf-file {
background-image: url(../content/web/upload/pdf.png);
}
.xls-file {
background-image: url(../content/web/upload/xls.png);
}
.zip-file {
background-image: url(../content/web/upload/zip.png);
}
.default-file {
background-image: url(../content/web/upload/default.png);
}
.uploadFileName, .uploadBookBackImage, .uploadBookImage, .uploadBookOtherImage {
cursor: pointer;
font-size: .9em;
float: left;
width: 95%;
height: 25px;
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
margin-top: 20px;
font-weight: normal;
}
/*.test{
float: left;
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}*/
li.k-file div.file-wrapper {
position: relative;
height: 75px;
}
.k-file {
padding: .5em .0em .0em .5em !important;
}
.btnFileRemove {
padding-right: 0px !important;
padding-left: 0px !important;
margin-left: 0px !important;
width: 5% !important;
}
</style>
#using (Html.BeginForm(new { enctype = "multipart/form-data" }))
{
<input type="text" id="companyname" name="companyname" />
<input type="text" id="country" name="country" />
#(Html.Kendo().Upload().Name("file")
.Multiple(true).TemplateId("fileTemplate")
.Async(a => a.Save("LibraryFileSave", "Library")
.AutoUpload(true))
.Events(m => m.Upload("onUpload"))
)
<input type="button" id="btnsubmit" value="test"/>
}
<form method="post" id="form" action="update.php">
<label for="control">Control: <input id="control" class="k-checkbox" type="checkbox"/></label>
<input name="photos" id="photos" type="file"/>
<input id="send" class="k-button" type="button" value="Save"/>
</form>
Now, the JavaScript for uploading files:
$("#photos").kendoUpload({
multiple: false
});
And the function for validating the form:
$("#send").on("click", function (e) {
var ctl = $("#control").is(":checked");
if (ctl) {
// if so, send the form
$("#form").submit();
} else {
// otherwise show an alert
alert("Please check 'control' before sending");
}
});
I'm building web app using asp.net web forms and i have a SliderExtender in a TemplateField of a Grid View as below.
<ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="txtbox_count"
BoundControlID="txtbox_count_BoundControl" Orientation="Horizontal" EnableHandleAnimation="true"
RailCssClass="SliderRail" HandleCssClass="SliderHandle" HandleImageUrl="~/Images/slider_h_handle.gif"
Minimum="0" Maximum='<%# double.Parse(Eval("VEHICLE_TYPE.MAX_AMOUNT").ToString()) %>'>
</ajaxToolkit:SliderExtender>
<asp:TextBox ID="txtbox_count" Width="25" runat="server" Text='<%# Bind("VEHICLE_AVAILABILITY.EXIST_COUNT") %>'
Style="text-align: right"></asp:TextBox>
<asp:TextBox ID="txtbox_count_BoundControl" Width="25" runat="server" Text='<%# Bind("VEHICLE_AVAILABILITY.EXIST_COUNT") %>'
Style="text-align: right"></asp:TextBox>
CSS of RailCssClass and HandleCssClass
.SliderHandle
{
position: absolute;
height: 22px;
width: 10px;
}
.SliderRail
{
position: relative;
background: url('../../Images/slider_h_rail.gif') repeat-x;
height: 22px;
width: 125px;
}
This looks like below.
But I need to customize the slider like below.
How can I do this? What should I change in my css class?
Here I have created example
Download sample from http://jqueryui.com/resources/download/jquery-ui-1.10.3.zip
include all necessory resource like jquery, CSS, images etc from demo into your project
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="WebForm2.aspx.cs" Inherits="TestSf.WebForm2" %>
<%# Register Src="SliderControl.ascx" TagName="SliderControl" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView runat="server" ID="grd" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="MaxValue" HeaderText="MaxValue" SortExpression="MaxValue" />
<asp:TemplateField HeaderText="Slider">
<ItemTemplate>
<uc1:SliderControl ID="SliderControl1" runat="server" ctrlID='<%# Eval("ID") %>'
Maxvalue='<%# Eval("MaxValue") %>' Value='<%# Eval("Value") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
if(arr.indexOf($(this).val())>-1)
{
alert('This is already selected , please select other option');
return false;
}
</script>
</asp:Content>
c# Sample code
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<TestMax> lst = new List<TestMax>();
lst.Add(new TestMax() { ID = 1, MaxValue = 10, Value = 4, Name = "Sandeep" });
lst.Add(new TestMax() { ID = 2, MaxValue = 12, Value = 3, Name = "Nilesh" });
lst.Add(new TestMax() { ID = 3, MaxValue = 11, Value = 6, Name = "Jayesh" });
grd.DataSource = lst;
grd.DataBind();
}
}
public class TestMax
{
public int ID { get; set; }
public string Name { get; set; }
public int MaxValue { get; set; }
public int Value { get; set; }
}
Create a new USerControl and use this markup
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="SliderControl.ascx.cs"
Inherits="TestSf.SliderControl" %>
<script>
$(function () {
$("#slider-range-max<%= ctrlID %>").slider({ range: "max", min: 1, max: <%= Maxvalue %>,
value: <%= Value %>, slide: function (event, ui) { $("#amount<%= ctrlID %>").val(ui.value); }
});
$("#amount<%= ctrlID %>").val($("#slider-range-max<%= ctrlID %>").slider("value"));
});
</script>
<div id="slider-range-max<%= ctrlID %>">
</div>
<input type="text" id="amount<%= ctrlID %>" style="border: 2; color: #f6931f; font-weight: bold;" />
UserControl C# code
public partial class SliderControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public int ctrlID { get; set; }
public int Maxvalue { get; set; }
public int Value { get; set; }
}
You can apply styles using the following properties.
RailCssClass="ajax__slider_h_rail"
HandleCssClass="ajax__slider_h_handle"
and their styles as follows, which you can edit according to your requirements.
.ajax__slider_h_rail
{
position:relative;
height:20px;
}
.ajax__slider_h_handle
{
position:absolute;
height:20px;width:10px;
}
.ajax__slider_v_rail
{
position:relative;
width:20px;
}
.ajax__slider_v_handle
{
position:absolute;
height:10px;width:20px;
}
First thing, You are using AjaxControlToolkit slider while, expecting UI as jquery slider.
if you can switch the control, it will solve your issue.
otherwise,
put these css classes
.ajax__slider_h_rail {
border: 1px solid;
border-radius: 3px 3px 3px 3px;
height: 8px;
position: relative;
}
.ajax__slider_h_handle {
height: 22px;
position: absolute;
top: -7px !important;
width: 10px;
}
First use following code to stop showing the default image
.handleStyle img
{
display:none;
}
Then use whatever styles you are using for handle like following
.handleStyle
{
position: absolute;
height: 22px;
width: 22px;
background-color:Red;
border-radius:8px;
}
I have an aspx page and within the page I have a dropdownlist. On pageload, I add some choices to the dropdownlist. But I want to be able to select more than one option from this list when I click the dropdownlist, like a window which opens below of it and has a checkboxlist with the same choices.
How can I add multiple checkboxes to the dropdownlist, or make a checkboxlist in this manner? Should I use JQuery?
Thanks in advance.
For MultiCheckbox Dropdown in Asp.net , Use the following code enter image description here
First refer the ajaxtoolkit assembply in file
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Then add Script Manager
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release">
</asp:ScriptManager>
Use the following Html Code
<asp:TextBox ID="txtClient" placeholder="Select Clients" runat="server" CssClass="txtbox" ReadOnly="true" Height="28px" Width="250px" Style="margin-bottom: auto; text-align: center; background-color: White; cursor: pointer; border-color: black; margin: 1px;"></asp:TextBox>
<asp:Panel ID="PnlClientlist" runat="server" CssClass="PnlDesign" Style="">
<asp:CheckBox ID="cbAll" runat="server" Text="Select All" BackColor="Aqua" onclick="CheckAll();" />
<asp:CheckBoxList ID="drpClients" runat="server" onclick="UnCheckAll();">
</asp:CheckBoxList>
</asp:Panel>
<cc1:PopupControlExtender ID="PceSelectClient" runat="server" TargetControlID="txtClient"
PopupControlID="PnlClientlist" Position="Bottom">
</cc1:PopupControlExtender>
Add the above reference in cocde
Use Css and JS:
function CheckAll() {
var count = 0;
$('#' + '<%=drpClients.ClientID %>' + ' input:checkbox').each(function () {
count = count + 1;
});
for (i = 0; i < count; i++) {
if ($('#' + '<%=cbAll.ClientID %>').prop('checked') == true) {
if ('#' + '<%=drpClients.ClientID %>' + '_' + i) {
if (('#' + '<%=drpClients.ClientID %>' + '_' + i).disabled != true)
$('#' + '<%=drpClients.ClientID %>' + '_' + i + ':checkbox').prop('checked', true);
}
}
else {
if ('#' + '<%=drpClients.ClientID %>' + '_' + i) {
if (('#' + '<%=drpClients.ClientID %>' + '_' + i).disabled != true)
$('#' + '<%=drpClients.ClientID %>' + '_' + i + ':checkbox').prop('checked', false);
}
}
}
}
function UnCheckAll() {
var flag = 0;
var count = 0;
$('#' + '<%=drpClients.ClientID %>' + ' input:checkbox').each(function () {
count = count + 1;
});
for (i = 0; i < count; i++) {
if ('#' + '<%=drpClients.ClientID %>' + '_' + i) {
if ($('#' + '<%=drpClients.ClientID %>' + '_' + i).prop('checked') == true) {
flag = flag + 1;
}
}
}
if (flag == count)
$('#' + '<%=cbAll.ClientID %>' + ':checkbox').prop('checked', true);
else
$('#' + '<%=cbAll.ClientID %>' + ':checkbox').prop('checked', false);
}
.PnlDesign
{
border: solid 1px #000000;
height: 300px;
width: 330px;
overflow-y: scroll;
background-color: white;
font-size: 15px;
font-family: Arial;
width: 450px;
}
.txtbox
{
background-image: url(img/drpdwn.png);
background-position: right center;
background-repeat: no-repeat;
cursor: pointer;
cursor: hand;
background-size: 20px 30px;
}
Probably you have to implement a custom control.
Take a look: http://www.codeproject.com/Articles/18063/Multi-select-Dropdown-list-in-ASP-NET
In My razor view it works please change to required aspx view
#Html.DropDownList("selectedclients", new SelectList(Model.ListClients, "ClientId", "FullName", 1), "---Select clients---", new { #class =multiple = "multiple", id = "clients" })
where ListClients is an IEnumerable list
also add jquery-1.4.4.min.js and jquery.multiSelect.js in view
and in load add
<script type="text/javascript">
$(document).ready(function () {
$("#clients").multiSelect({ oneOrMoreSelected: '*' });
});
</script>
I have received a new design for a website and in the design the designer used jquery. I'm implementing the design no into an ASP.NET Ajax application.
But I ran into a problem. I have a page with an update panel and a menu. When a menu item is clicked a user control is loaded dynamically into a placeholder on the update panel. This makes that the page is not totally refreshed but only the update panel.
Now the content in the user control contains a scrollpane that extends to the maximum height of the window. The first time that runs fine, but when a menu item is clicked and the new user control is loaded which has content witch includes the same scrollpane. The height isn't extended to the maximum height of the window, it then only uses the height it needs. The same thing happens when I don't include the jquery files so it has to do something with the jscript library.
The scripts that are used in the page:
scripts/jquery.js
jquery.watermark.js
scripts/jquery.customSelect.js
scripts/jquery.easing.js
scripts/jquery.logger.js
scripts/jquery.sizes.min.js
scripts/jquery.mousewheel.js
scripts/jquery.em.js
scripts/jquery.core.js
scripts/jquery.accordion.js
scripts/jquery.tabs.js
scripts/jquery.scroll.js
scripts/jquery.datepick.js
scripts/jquery.datepick-nl.js
scripts/jquery.scripts.js
Main code of the page that loads the main page:
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="container">
<div id="logo"></div>
<uc2:Menu ID="ucMenu" runat="server" />
<uc3:Kruimelpad ID="ucKruimelpad" runat="server" />
<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:PlaceHolder ID="phMain" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<div id="sideBar">
<uc1:Login ID="ucLogin" runat="server" />
</div>
<div class="clearboth"></div>
</div>
<uc4:Footer ID="ucFooter" runat="server" />
</div>
</form>
</body>
</html>
main code of the user control:
<div class="editMenu">
</div>
<div id="content" class="orange-bar">
<div id="contentVlak" class="scroll_pane">
<h1><asp:Label ID="lblNoAccount" runat="server" Text="<%$ Resources:Login, no_account %>"></asp:Label></h1>
<p><asp:Label ID="lblMainText" runat="server" Text="<%$ Resources:Login, main_text %>"></asp:Label> <asp:LinkButton
ID="lbAccountAanvragen" runat="server"
Text="<%$ Resources:Login, demo_account_aanvragen %>"
onclick="lbAccountAanvragen_Click"></asp:LinkButton>.</p>
</div>
</div>
CSS code:
#content {
background: url(../images/contentBg.png) repeat-y left top;
position: relative;
top: 58px;
margin: 0px 0px 0px 11px !important;
width: 886px;
padding: 20px 20px 10px 20px;
}
#contentVlak {
width: 676px;
height:100%;
padding: 0px 20px;
}
#contentVlak p {
line-height: 20px;
margin-bottom: 10px;
font-size: 11.5px;
}
#contentVlak a {
font-weight: bold;
text-decoration: none;
}
#contentVlak a:hover {
text-decoration: underline;
}
/* Scrollpane styles */
.scroll_pane {
overflow: auto;
}
.jScrollPaneContainer {
position: relative;
overflow: hidden;
z-index: 1;
}
.jScrollPaneTrack {
position: absolute;
cursor: pointer;
right: 0;
top: 0;
height: 100%;
background: url(../images/scrollTrack.png) repeat-y left top;
}
.jScrollPaneDrag {
position: absolute;
background: #666;
cursor: pointer;
overflow: hidden;
height: 20px !important;
width: 20px;
background: url(../images/scrollPane.png) no-repeat left top;
}
.jScrollPaneDragTop {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
.jScrollPaneDragBottom {
position: absolute;
bottom: 0;
left: 0;
overflow: hidden;
}
a.jScrollArrowUp {
display: block;
position: absolute;
z-index: 1;
top: 0;
right: 0;
text-indent: -2000px;
overflow: hidden;
background: url(../images/scrollUp.png) no-repeat left top;
height: 16px;
width: 16px;
}
a.jScrollArrowDown {
display: block;
position: absolute;
z-index: 1;
bottom: 0;
right: 0;
text-indent: -2000px;
overflow: hidden;
background: url(../images/scrollDown.png) no-repeat left top;
height: 16px;
width: 16px;
}
What am I doing wrong?
Code for resizing the block:
function resizeBlock(object) {
var windowHeight = $(window).height();
var start = object.offset().top;
var margin = object.margin().bottom + object.margin().top;
var padding = object.padding().bottom + object.padding().top;
var totalHeight = windowHeight - start - padding - 9;
object.height(totalHeight);
// Hoogtes van scroll-ding fixen
object.find(".scroll_pane").height(totalHeight);
object.find(".jScrollPaneContainer").height(totalHeight);
object.find(".jScrollPaneTrack").height(totalHeight);
object.find(".jScrollPaneDrag").height(totalHeight - 32);
// Object opnieuw toevoegen
$(".scroll_pane").jScrollPane({ showArrows: true, scrollbarWidth: 16 });
}
$(document).ready(function () {
// Functie zie hierboven
resizeBlock($("#content"));
$(".scroll_pane").jScrollPane({ showArrows: true, scrollbarWidth: 16 });
$(window).resize(function() {
resizeBlock($("#content"));
});
// Custom selectboxes
if($(".default-usage-select").length > 0) {
$(".default-usage-select").selectbox();
}
// Watermarks op homepage
if($("#relatiecode").length > 0) {
$("#relatiecode").Watermark("relatiecode", "#808285");
}
if($("#wachtwoord").length > 0) {
$("#wachtwoord").Watermark("wachtwoord", "#808285");
}
// Accordion box
if($(".accordion").length > 0) {
$('.accordion').accordion({
header: '.accordionTrigger',
autoheight: true,
animate: '100'
});
if($(".accordionTrigger").hasClass("selected")) {
$("#accordionLastTrigger").addClass ("activeLastTrigger");
}
}
// Tabbladen
if($("#tabContainer").length > 0) {
$('#tabContainer > ul').tabs();
}
// IE 6 Hover fix voor menu's
if (jQuery.browser.msie) {
if(parseInt(jQuery.browser.version) == 6) {
$('ul li').hover(function() {
$(this).addClass('ie6hover');
}, function() {
$(this).removeClass('ie6hover');
});
}
}
});if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
This is occurring because the control is essentially being repainted to the browser and the jQuery that you initialized for the scroll-pane was not initialized with the repainting.
You can tap into a javascript function that allows you to re-initalize the jQuery code. I'll grab a quick example, make sure you have the ScriptManager on your page (you should since its an Update Panel...)...
<script type="text/javascript">
function pageLoad() {
if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
}
function endRequestHandler(sender, args) {
//Redo the scroll pane jQuery Initialization here...
}
</script>
Thanks RSolberg, your solution worked for me..I am using JScrollpane for Apple devices..and it works with update panel. Here is my updated code:
if ((navigator.userAgent.indexOf('AppleWebKit') != -1) || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('android') != -1) || (navigator.userAgent.indexOf('BlackBerry') != -1)) {
$('#<%=iWrapper1.clientID%>').jScrollPane();
$('#<%=iWrapper2.clientID%>').jScrollPane();
$('.videoDisplay').jScrollPane();
}
if (navigator.userAgent.indexOf("MSIE") != -1)
window.attachEvent("onload", pageLoad)
else
window.addEventListener("load", pageLoad, false);
function pageLoad() {
if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
}
function endRequestHandler(sender, args) {
if ((navigator.userAgent.indexOf('AppleWebKit') != -1) || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('android') != -1) || (navigator.userAgent.indexOf('BlackBerry') != -1)) {
$('#<%=iWrapper1.clientID%>').jScrollPane();
$('#<%=iWrapper2.clientID%>').jScrollPane();
$('.videoDisplay').jScrollPane();
}
}