RadhaKrishnaKiJaya
asked on
Disable the form when any button or dropdown is clicked ASP.Net VB.Net
Hi Experts,
I have a form with dropdowns and buttons. When I select a 'Location' from the dropdown, it fills the 'Rooms' and generate a financial report for that 'Location'. I have written all the server side code in 'Onchange' event. I want to disable the form so that no body should able to click anything else while this operation is going on and display some wait message. How can I do this. Please help.
Thanks in advance.
I have a form with dropdowns and buttons. When I select a 'Location' from the dropdown, it fills the 'Rooms' and generate a financial report for that 'Location'. I have written all the server side code in 'Onchange' event. I want to disable the form so that no body should able to click anything else while this operation is going on and display some wait message. How can I do this. Please help.
Thanks in advance.
ASKER
Hi,
Thanks for your reply. Actually I need to disable the whole page when some operation is going on with some 'Wait' message. I have attached a screen shot of what I want.
Thanks you.
Loading.png
Thanks for your reply. Actually I need to disable the whole page when some operation is going on with some 'Wait' message. I have attached a screen shot of what I want.
Thanks you.
Loading.png
check this
https://jsfiddle.net/d02brj5L/
we show a div which covers all area and then hide it to enable everything...
https://jsfiddle.net/d02brj5L/
$("#btnDisable").on("click", function() {
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
we show a div which covers all area and then hide it to enable everything...
ASKER
I have copied your program and trying to run it. But getting this error. Please suggest.
<head>
<title></title>
<style type="text/css">
.form {
padding: 10px;
margin: 10px;
border: 1px dotted silver;
}
#divWait {
position: absolute;
top: 0px;
right: 0px;
width: 100%;
height: 100%;
background-color: #666;
background-image: url('ajax-loader.gif');
background-repeat: no-repeat;
background-position: center;
z-index: 10000000;
opacity: 0.4;
filter: alpha(opacity=40);
display: none;
text-align: center;
}
</style>
<script type="text/javascript">
$("#btnDisable").on("click ", function () {
//$("#myForm :input").attr("disabled", true);
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
</script>
</head>
<form id=myForm class=form>
click something button...
<br>
<input id=txt1>
<br>
<textarea></textarea>
<br>
<select>
<option>Option A</option>
<option>Option B</option>
<option>Option C</option>
</select>
<br>
<button>
send
</button>
</form>
<button id=btnDisable>
Disable
</button>
<div id="divWait">
<div>
<img src="http://www.healthytweeting.com/images/ogwait.gif">
</div>
</div>
Error.png
<head>
<title></title>
<style type="text/css">
.form {
padding: 10px;
margin: 10px;
border: 1px dotted silver;
}
#divWait {
position: absolute;
top: 0px;
right: 0px;
width: 100%;
height: 100%;
background-color: #666;
background-image: url('ajax-loader.gif');
background-repeat: no-repeat;
background-position: center;
z-index: 10000000;
opacity: 0.4;
filter: alpha(opacity=40);
display: none;
text-align: center;
}
</style>
<script type="text/javascript">
$("#btnDisable").on("click
//$("#myForm :input").attr("disabled", true);
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
</script>
</head>
<form id=myForm class=form>
click something button...
<br>
<input id=txt1>
<br>
<textarea></textarea>
<br>
<select>
<option>Option A</option>
<option>Option B</option>
<option>Option C</option>
</select>
<br>
<button>
send
</button>
</form>
<button id=btnDisable>
Disable
</button>
<div id="divWait">
<div>
<img src="http://www.healthytweeting.com/images/ogwait.gif">
</div>
</div>
Error.png
check my demo & source code...
https://jsfiddle.net/d02brj5L/
1. you need jQuery library, on top, between head tags
2. code should be wrapped in jQuery DOM ready function, place anywhere...
https://jsfiddle.net/d02brj5L/
1. you need jQuery library, on top, between head tags
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
2. code should be wrapped in jQuery DOM ready function, place anywhere...
$(function(){
... your jquery code here
};
ASKER
It is working for a button. But I want for a dropdown list too. So I am trying to add the code for 'change' event. But it does not work. Also instead of 5 sec timer can we make it dynamic? It should close after the loading is done.
Thanks for your help.
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#ddlLocations").on("change", function () {
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
});
</script>
Thanks for your help.
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#ddlLocations").on("change", function () {
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
});
</script>
for above code work, you need to have an element that can change / have change event with id=ddlLocations
see this
https://jsfiddle.net/wr53h8bp/
you can call it anywhere anytime...
I put 5 sec timer to demonstrate how enable / disable will work...
you will hide that whenever required...
see this
https://jsfiddle.net/wr53h8bp/
you can call it anywhere anytime...
I put 5 sec timer to demonstrate how enable / disable will work...
you will hide that whenever required...
ASKER
Thanks for trying to help me. But for some reason it does not work with my code. Please help.
<asp:Content ID="Content1" ContentPlaceHolderID="Titl eContentPl aceHolder" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head " Runat="Server">
<link href="/css/AllPages.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#ddlLocations").on("cha nge", function () {
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main ContentPla ceHolder" Runat="Server">
<div id="page-wrapper">
<div id="page-inner">
<div class="row">
<div class="col-lg-12">
<h3>ADMIN DASHBOARD</h3>
</div>
</div>
<div class="MessageDiv">
<table>
<tr>
<td> <asp:Label ID="lblMessage" runat="server" Text="Label" CssClass ="label" Visible="false" ></asp:Label></td>
</tr>
</table>
</div>
<hr />
<div id="divWait" class ="divWait">
<div>
<img src="http://www.healthytweeting.com/images/ogwait.gif">
</div>
</div>
<div class="InputDiv SpaceDiv">
<div style="width:100%;float:le ft;">
<table class="inputtables">
<tr>
<td colspan="2" style="padding-left:5px">C ustomer:</ td>
<td colspan="2">
<asp:DropDownList ID="ddlCustomer" runat="server" TabIndex="1" CssClass ="MediumDropDown" AutoPostBack ="true" >
</asp:DropDownList>
</td>
<td colspan="1">Location:</td>
<td colspan="2">
<asp:DropDownList ID="ddlLocations" runat="server" TabIndex="2" CssClass ="MediumDropDown" AutoPostBack ="true">
</asp:DropDownList>
</td>
<td colspan="1">Room:</td>
<td colspan="1" style="padding-left:5px">
<asp:DropDownList ID="ddlRooms" runat="server" TabIndex="2" CssClass ="MediumDropDown" AutoPostBack ="true">
</asp:DropDownList>
</td>
<td colspan="1">Select Date:</td>
<td colspan="2">
<asp:TextBox ID="txtSelectedDate" runat="server" CssClass="MediumTextBox" AutoPostBack ="true" ></asp:TextBox>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Titl
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head
<link href="/css/AllPages.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#ddlLocations").on("cha
$("#divWait").show();
setTimeout(processEnd, 5000);
});
function processEnd() {
$("#divWait").hide();
}
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main
<div id="page-wrapper">
<div id="page-inner">
<div class="row">
<div class="col-lg-12">
<h3>ADMIN DASHBOARD</h3>
</div>
</div>
<div class="MessageDiv">
<table>
<tr>
<td> <asp:Label ID="lblMessage" runat="server" Text="Label" CssClass ="label" Visible="false" ></asp:Label></td>
</tr>
</table>
</div>
<hr />
<div id="divWait" class ="divWait">
<div>
<img src="http://www.healthytweeting.com/images/ogwait.gif">
</div>
</div>
<div class="InputDiv SpaceDiv">
<div style="width:100%;float:le
<table class="inputtables">
<tr>
<td colspan="2" style="padding-left:5px">C
<td colspan="2">
<asp:DropDownList ID="ddlCustomer" runat="server" TabIndex="1" CssClass ="MediumDropDown" AutoPostBack ="true" >
</asp:DropDownList>
</td>
<td colspan="1">Location:</td>
<td colspan="2">
<asp:DropDownList ID="ddlLocations" runat="server" TabIndex="2" CssClass ="MediumDropDown" AutoPostBack ="true">
</asp:DropDownList>
</td>
<td colspan="1">Room:</td>
<td colspan="1" style="padding-left:5px">
<asp:DropDownList ID="ddlRooms" runat="server" TabIndex="2" CssClass ="MediumDropDown" AutoPostBack ="true">
</asp:DropDownList>
</td>
<td colspan="1">Select Date:</td>
<td colspan="2">
<asp:TextBox ID="txtSelectedDate" runat="server" CssClass="MediumTextBox" AutoPostBack ="true" ></asp:TextBox>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</asp:Content>
try
or use class
> will be used for all dropdowns with that class... or use this
to add that function to all dropdown and text box...
demo, https://jsfiddle.net/cxqzbteq/
$("<%=ddlCustomer.ClientID%>").on("change", function () {
or use class
$(".MediumDropDown").on("change", function () {
> will be used for all dropdowns with that class... or use this
$(".MediumDropDown, .MediumTextBox").on("change", function () {
to add that function to all dropdown and text box...
demo, https://jsfiddle.net/cxqzbteq/
ASKER
Hi,
Thanks for your time and help.
$(".MediumDropDown").on("c hange", function () { This one worked. Please help me with the last thing. now it is running for 5000ms. How can I change it , so that it will run till the processing is done and close after that.
This is the code running when I change the Location. I need to make sure it is disable till the financial data and rooms are load.
Protected Sub ddlLocations_SelectedIndex Changed(se nder As Object, e As EventArgs) Handles ddlLocations.SelectedIndex Changed
Try
ddlRooms.Items.Clear()
lblMessage.Text = ""
lblMessage.Visible = False
mnuCalender.SelectedDates. Clear()
If ddlLocations.Text <> "---Select Location---" Then
Dim dsRooms As DataSet = Get_Rooms(ddlLocations.Sel ectedValue , lblMessage)
If dsRooms.Tables(0).Rows.Cou nt > 0 Then
ddlRooms.DataSource = dsRooms
ddlRooms.DataValueField = "RoomID"
ddlRooms.DataTextField = "RoomName"
ddlRooms.DataBind()
ddlRooms.Items.Insert(0, "---Select Room---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText( "---Select Room---").Value
Dim CurrentMonth As String = DateTime.Now.Month.ToStrin g()
Dim CurrentYear As String = DateTime.Now.Year.ToString ()
Dim MonthName As String = DateTime.Today.ToString("M MMM")
'txtSelectMonthYear.Text = MonthName & " " & CurrentYear
Load_Customer_Financial_Da ta(ddlCust omer.Selec tedValue, ddlLocations.SelectedValue , CurrentMonth, CurrentYear)
Else
ddlRooms.Items.Insert(0, "---No Room Found---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText( "---No Room Found---").Value
ReportDiv.Visible = False
End If
Else
ddlRooms.Items.Insert(0, "---No Room Found---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText( "---No Room Found---").Value
ReportDiv.Visible = False
End If
Catch ex As Exception
MessageBox("Problem during changing the Location!! " & ex.Message, lblMessage)
End Try
End Sub
Thanks for your time and help.
$(".MediumDropDown").on("c
This is the code running when I change the Location. I need to make sure it is disable till the financial data and rooms are load.
Protected Sub ddlLocations_SelectedIndex
Try
ddlRooms.Items.Clear()
lblMessage.Text = ""
lblMessage.Visible = False
mnuCalender.SelectedDates.
If ddlLocations.Text <> "---Select Location---" Then
Dim dsRooms As DataSet = Get_Rooms(ddlLocations.Sel
If dsRooms.Tables(0).Rows.Cou
ddlRooms.DataSource = dsRooms
ddlRooms.DataValueField = "RoomID"
ddlRooms.DataTextField = "RoomName"
ddlRooms.DataBind()
ddlRooms.Items.Insert(0, "---Select Room---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText(
Dim CurrentMonth As String = DateTime.Now.Month.ToStrin
Dim CurrentYear As String = DateTime.Now.Year.ToString
Dim MonthName As String = DateTime.Today.ToString("M
'txtSelectMonthYear.Text = MonthName & " " & CurrentYear
Load_Customer_Financial_Da
Else
ddlRooms.Items.Insert(0, "---No Room Found---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText(
ReportDiv.Visible = False
End If
Else
ddlRooms.Items.Insert(0, "---No Room Found---")
ddlRooms.SelectedValue = ddlRooms.Items.FindByText(
ReportDiv.Visible = False
End If
Catch ex As Exception
MessageBox("Problem during changing the Location!! " & ex.Message, lblMessage)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
how come you can use
in a web application? there is no such thing, this is web app not windows form app!
unless it is a custom function that you wrote! which is just simple javascript:alert() function...
MessageBox("Problem during changing the Location!! " & ex.Message, lblMessage)
in a web application? there is no such thing, this is web app not windows form app!
unless it is a custom function that you wrote! which is just simple javascript:alert() function...
ASKER
Thank you very much for your wonderful help!!!
https://jsfiddle.net/h89rg8fu/
enable/disable all form elements on client side...
Open in new window