Textbox disabled automatically after postback
In a ASP.NET form there are two textbox controls. One control set today's date and another control initially disabled. Based on date enable the control (disabled property). If date is current date, disable the textbox, else enable the control. It worked well.
Now the date is not today and text box is enabled. But when click the button, the form is posted back and the text box is disabled again. I didn't set enable/disable setting in any other places in javascript and code behind. I am not sure why this is happening.
if (condition)
{
$('#txt').prop('disabled', true); }
else
{
$('#txt').prop('disabled', false);
}
If anyone faced this kind of issue and any solution available, please help me to resolve this.
1 answer
-
answered 2021-01-18 17:21
Albert D. Kallal
Well, if there is a post-back, then why not set the enable with code behind?
eg:
DateTime dtToday = DateTime.Today; if (TextBox1.Text == dtToday.ToShortDateString()) TextBox2.Enabled = false; else TextBox2.Enabled = true;
So, above in the on-load of the page should work rather well.
Now I like client side code (js), but if a post back is going to occur here, then might as well run code behind to manage this.
See also questions close to this topic
-
How can I download a EXCEL flle(in direcctory 1) residing in my local directory(any usual directory2) using CodeIgniter?
I am new to Codeigniter and was working to download a file let say that resides in c:/downloads(an excel file, CSV) to my usual download folder, I am using Wamp server and Codeigniter-3, anything I have gone through does not make any sense to me. Is there a way to do that?
Thanks for any contribution in advance.
-
clear cart from session , and after logging it to console i get empty array but when visit cart view i still get cart items
I am working on e-commerce project , after checkout i wrote a code that deletes the cart items , and just to make sure i console.log(req.session.cart), and it shows an empty array means that session.cart is empty , but then i redirect user to home page , but then on home page i still get cart and its items , how to solve this problem? thanks .
this is how i cleared my cart its working fine!
order.save().then((r) => { // console.log(r) console.log("after checkout") for (let index = 0; index < req.session.cart.length; index++) { req.session.cart.splice(index) } console.log("Cart after clearing items ") console.log(req.session.cart
but if I revisit my cartView route i still get cart adn its items
router.get('/viewCarts', (req, res) => { console.log("cart items ",req.session.cart) catSchema.find({}).then((categories) => { // console.log(req.session.cart) res.render('../views/cartView/cartView.ejs', { layout: '../views/welcome/welcomeHeader.ejs', options: 'BUY', title: 'MY CART', cat: categories, cart:req.session.cart }); }); });
-
I want to download Multiple images as a zip file using javascript
I am trying to download multiple image when i click to download button but unfortunately i am getting empty folder in zip file , images or files are not downloading in zip file please help me how can i resolve that ? thanks.
Note :- I am getting images or files in array from db like this ["zFbf2cGRPLTaXbqzA5VWt8FZTjhXkt4LoC041fIH.jpeg","ucy0WknOKMhuNtfqcRgmWUgpvp2IPKhU84lU2tAq.jpeg"]
html view
<a href="javascript:;" class="download text-primary p-5" data-original-title="Download Files" title="" data-placement="top" data-toggle="tooltip" > <i class="fa fa-download" aria-hidden="true"></i> </a>
script
let url="{{Config('yourstitchart.file_url')}}" //url = http://localhost/yourstitichart/yourstitichart.com/web/public/uploads/images/ window.onload = function(event) { let val= document.querySelector('.download') let files= {!!$event->image_gallery!!} // let files=["zFbf2cGRPLTaXbqzA5VWt8FZTjhXkt4LoC041fIH.jpeg", // "ucy0WknOKMhuNtfqcRgmWUgpvp2IPKhU84lU2tAq.jpeg"] var zip = new JSZip(); var folder = zip.folder("files"); files.map(async item=>folder.file(url+item)) val.addEventListener("click",(e)=>{ zip.generateAsync({type:"blob"}) .then(function(content) { saveAs(content, "example.zip"); }); }); } }, },
-
Why am i getting 'A column already belongs to this DataTable.' exception at dt.Columns.Add(header)?
I have the following tsv file: (columns start from
StyleName
and end atCurrent Prod PS
)StyleName Desc Box Count MinPerQ1 MaxPerQ1 SNDContainsPS SNDSpecifiedPSIs CurrentCommonProdID ProductIDs SND Indicates PS? PS Specified In SND Is Currently mapped to Current Prod PS Custom (Sphere Design) Lens 1 357 357 0 NULL 398497 45222275 No NA __Misc GB | Vial 1 PLASMA TREAT PLASMA TREAT 1 11 11 0 NULL -2 38953746 No NA __Unmappable
I am trying to convert the tsv file into a DataTable because after some research, I found that Datatable will make my use case easier to manipulate later on (I want to insert a column into this tsv file later on from another tsv file, which is outside the scope of this question).
I am getting this error at
dt.Columns.Add(header);
:'A column named 'SND Indicates PS?' already belongs to this DataTable.'
Why is that? I searched for the
SND Indicates PS?
keyword and the only one i see is the column name, theres no duplicates whatsover...so how come this exception is being thrown?public static DataTable ConvertCSVtoDataTable(string strFilePath, char delimiter = '\t') { DataTable dt = new DataTable(); using (StreamReader sr = new StreamReader(strFilePath)) { string[] headers = sr.ReadLine().Split(delimiter); foreach (string header in headers) { dt.Columns.Add(header); } while (!sr.EndOfStream) { string[] rows = sr.ReadLine().Split(delimiter); DataRow dr = dt.NewRow(); for (int i = 0; i < headers.Length; i++) { dr[i] = rows[i]; } dt.Rows.Add(dr); } } return dt; }
-
Why Point with random X and Y results always on the same line?
I know that Random isn't totally random and it gives same result repeatedly if use it with a very little span. However, i was just playing around with it and came up with a very interesting result.
Here is my code :
private void Form1_Load(object sender,EventArgs e) { timer1.Enabled = true; timer1.Interval = 1000;//i was hoping that interval will change result but no luck. } private void timer1_Tick(object sender,EventArgs e) { Label label = new Label(); label.Visible =true; label.Text = " "; label.AutoSize = true; Random rndX = new Random(); Random rndY = new Random();//I know i don't actually need this. Point point = new Point(){X=rndX.Next(0,1000),Y=rndY.Next(0,1000)}; label.Location = point; label.BackColor = Color.FromArgb(rnd.Next(1,255),rnd.Next(1,255),rnd.Next(1,255)); this.Controls.Add(label); }
Why is random behaving like this?
Also is there a way to make this truely random?
-
Remove punctation within string
I would like to remove a punctation within a string. The punctuation before a space should be preserved. Double punctuation should also not be removed.
Hel-lo World --> Hello World Hel.lo Wo-rld --> Hello World approx. age --> approx. age approx.-age --> approx.-age
So far i got this. But it replaces all punctations ... and covers only case 1 and 2
Regex.Replace("Hel-lo World!", @"[^\w\s]", "");
-
When triggering to check all checkboxes, how do you prevent other checkboxes from being checked on other pages inside dataTables using jQuery
Since I used dataTables and put it inside a
<form>
to pass data to the server, I discovered that I cannot pass all the data inside per page, cause other elements<td>
are hidden so in able to send it all to the database I need to sort them depending onshow entities
10 - 100. But what I want to do is this. If I click the checkbox I made to select all checkboxes on that particular page it should not select the other checkboxes from other pages. How should I do that? Any ideas? Thanks you in advance for the help.Here is the code example
//Selecting all checkboxes that are not disabled $("#select_all").on('click', function() { $('#dataTables').DataTable() .column(3) .nodes() .to$() .find('input[type="checkbox"]:enabled') .prop('checked', this.checked); }); // Sorting of column in dataTables $(document).ready(function() { $("#dataTables").DataTable({ aaSorting: [ [2, 'asc'] ], bPaginate: true, bFilter: true, bInfo: true, bSortable: true, bRetrieve: true, aoColumnDefs: [{ "aTargets": [0], "bSortable": true }, { "aTargets": [1], "bSortable": true }, { "aTargets": [2], "bSortable": true }, { "aTargets": [3], "bSortable": false } ] }); });
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/css/bootstrap-select.min.css" integrity="sha512-ARJR74swou2y0Q2V9k0GbzQ/5vJ2RBSoCWokg4zkfM29Fb3vZEQyv0iWBMW/yvKgyHSR/7D64pFMmU8nYmbRkg==" crossorigin="anonymous" /> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.18/js/bootstrap-select.min.js" integrity="sha512-yDlE7vpGDP7o2eftkCiPZ+yuUyEcaBwoJoIhdXv71KZWugFqEphIS3PU60lEkFaz8RxaVsMpSvQxMBaKVwA5xg==" crossorigin="anonymous"></script> <div class="row"> <div class="col-lg-6"> <div class="panel panel-default"> <div class="panel-heading"> Sample </div> <!-- /.panel-heading --> <div class="panel-body"> <div class="table-responsive"> <table id="dataTables" class="table table-striped table-bordered table-hover"> <thead> <tr> <th>#</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th> <center> Select <input type="checkbox" id="select_all"> </center> </th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Mark</td> <td>Otto</td> <td>@mdo</td> <td> <center> <input type="checkbox" id="select_all"> </center> </td> </tr> <tr> <td>2</td> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> <td> <center> <input type="checkbox" id="select_all"> </center> </td> </tr> <tr> <td>3</td> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> <td> <center> <input type="checkbox" id="select_all"> </center> </td> </tr> </tbody> </table> </div> <!-- /.table-responsive --> </div> <!-- /.panel-body --> </div> <!-- /.panel --> </div> <!-- /.col-lg-6 --> </div>
-
Bootstrap modal flickers when clicked on another button having a modal popup
I have a button that, when clicked, pops up a Bootstrap modal. Here is the code
function confirm_deactivation(row, user_id, status_field) { const modal_elem = $("#deactivation_user_modal").expectOne(); function set_fields() { const user = people.get_by_user_id(user_id); modal_elem.find(".email").text(user.email); modal_elem.find(".user_name").text(user.full_name); } function handle_confirm() { const row = get_user_info_row(user_id); modal_elem.modal("hide"); const row_deactivate_button = row.find("button.deactivate"); row_deactivate_button.prop("disabled", true).text(i18n.t("Working…")); const opts = { success_continuation() { update_view_on_deactivate(row); }, error_continuation() { row_deactivate_button.text(i18n.t("Deactivate")); }, }; const url = "/json/users/" + encodeURIComponent(user_id); settings_ui.do_settings_change(channel.del, url, {}, status_field, opts); } modal_elem.off("click", ".do_deactivate_button"); set_fields(); modal_elem.on("click", ".do_deactivate_button", handle_confirm); modal_elem.modal("show"); } function handle_deactivation(tbody, status_field) { tbody.on("click", ".deactivate", (e) => { // This click event must not get propagated to parent container otherwise the modal // will not show up because of a call to `close_active_modal` in `settings.js`. e.preventDefault(); e.stopPropagation(); const row = $(e.target).closest(".user_row"); const user_id = row.data("user-id"); confirm_deactivation(row, user_id, status_field); }); }
I have a list of such buttons (with class="deactivate").
The problem is when I click a button, the modal pops up, but when I click on another button, while this modal is on, the new modal appears and then instantly hides. If I click again on the button, the modal just appears and then instantly hides.
Can anyone please help me with why is this happening?
-
Which loop is better for array of object in reactjs?
Object ={[{name:"a",age:"12"},{name:"a",age:"12"},{name:"a",age:"12"}]}
which loops better for faster response for this Object in react
-
how to get all controls of aspx page without running in browser
I have aspx page which may controls. I want get all controls of aspx page without running into browser. Means by taking physical path, I want to get list of all controls from aspx.
for example - I have following aspx page and I want to get all controls(textbox and label) and their attributes.
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:Content>
-
using select options to get value in asp.net razor page
I want to create a select option to input one of a few fixed values and have it return a matching value to a variable similar to how the input text fields, how would I do this? This was my attempt, the
<input type="text">
works fine but the select types return null.<div class="text-center"> <h1 class="display-4">Add new patient</h1> <form method="post"> <input type="text" asp-for="patientModel.PatientID" placeholder="Patient ID" /> <input type="text" asp-for="patientModel.FirstName" placeholder="First Name" /> <input type="text" asp-for="patientModel.SecondName" placeholder="Second Name" /> <input type="text" asp-for="patientModel.Location" placeholder="Location" /> <select id="active" name="active" asp-for="patientModel.Sex"> <option value="ACTIVE">MALE</option> <option value="INACTIVE">FEMALE</option> <option value="OTHER">OTHER</option> </select> <select id="active" name="active" asp-for="patientModel.Active"> <option value="ACTIVE">ACTIVE</option> <option value="INACTIVE">INACTIVE</option> </select> <button type="submit">Submit</button> </form> </div>
public class addnewpatientModel : PageModel { [BindProperty] public PatientModel patientModel { get; set; } public void OnGet() { } public IActionResult OnPost() { return RedirectToPage("/index"); } }
-
Solution for contenteditable="true" property is not working for image tag when resize image in Chrome and Firefox
I want to resize the image inside the img tag in a div. I am using contenteditable="true" property for the div. I am editing the content but I do not select the image and resize the image in chrome and firefox
my code is simple
div contenteditable="true" img src="img.png" div
This code is working in the IE browser and I am selecting an image and also resize the image but in chrome and firefox, it won't work for me.
Please give some solution. Thank you