i have an AJAXIFIED button(btnsend) thas is disable by it's Property -> Enabled="False"
i have a TextBox Next To This Button And I Want Enable that Button When Users Type Something in That TextBox...
so i did this (JavaScript):
function onkeyupontextbox() {
var btnSend = document.getElementById("btnSend");
btnSend.disabled = false;
}
but that button does not work after becomes enable...
what can i do about that?
(i am using radajaxmanager for ajaxify that button)
(when i remove that button from RadAjaxmanager Or UpdatePanel So EveryThing Is Ok , But I Want That Button In Ajaxify Mode)
thanks for your attention...
Sounds like you're trying to mix Ajaxified properties and DOM element properties.
Leave the property Enabled = "True" when you ajaxify it, then use JS on page load to btnSend.disabled = true it. If you use pure js to disable it the function you have above should work fine to re-enable it. For example, if the ajaxify property 'Enabled' is set to true, then place the following javascript into your page:
window.onload = function(){
document.getElementById("btnSend").disabled = true;
};
Then use the function you wrote above to enable it onkeyupontextbox(). Because javascript is disabling the button, it should be able to re-enable it. Before, you were disabling with the Ajaxified property and trying to re-enable with js.
Could following be the answer? (Dont have experiences with RadAjaxmanager)
function EnableBtnSend()
{
$find("<%=btnSend.ClientID %>").ajaxRequest("");
}
Found here: http://www.telerik.com/help/aspnet-ajax/grdenabledconventions.html
Related
I want to enable and disable all the controls on .cshtml from at client side. As this functionality is general for all the pages and no. of controls are not fixed, i do not want to enable and disable individual control. There must be some way by which all the controls must get disabled/enabled on checkbox click. I am using #HTML helper classes to generate the input controls,following is the example for same
#Html.Label("lblEnableDisableTimeGen", "txt_EnableDisableTimeGen", "EnableDisableTimeGen")
#Html.CheckBox("chkEnableTimeGenProgram",true)
I found out the way to do so. Here is the example
Define all your controls in a div.
e.g :
control1....
control2....
</div>
use the script below to enable and disable all the controls within div
function EnableDisable()
{
dojo.query("input, button, textarea, Select, div",
TimeGenProgramEnableDisable).attr("disabled", !chkEnableDisable.checked);
}
Mind it here we are using DOJO toolkit
You can try this:
//Code Starts
$(document).ready(function() {
$("#btnDisable").click(function(e) {
$("*").attr("disabled", "disabled");
e.preventDefault();
});
});
//Code Ends
Use JQuery on the page:
function toggleChecked(status) {
$("INPUT[type='checkbox']").each( function() {
$(this).attr("checked",status);
})
This checks all checkboxes on your page. You can use it with a button's onClick, for example:
onclick="togggleChecked(true)";
Is using javascript an option?
You could set up a click handler on the checkbox and then simply disable all the inputs on the form
if jquery allowed try this,,
to disable:
$("#parent-selector :input").attr("disabled", "disabled");
to enable:
$("#parent-selector :input").removeAttr("disabled");
I have an asp.net webform with a few Panels that each have several textboxes inside of it. I am currently hiding or displaying the panel using jQuery based on which item in a DropDownList is selected.
I have run into an issue where the required field validator is still firing even when the elements it is attached to is not showing because it's parent panel has display: none.
Is there any way to disable the RequiredFieldValidator when the element it is attached to is not showing because of CSS?
I know that if set Visible=false on the server side the elements wouldn't render at all, but I would prefer to keep the show/hide logic on the client side for user experience reasons.
I agree that a custom validator would be best, but if you do need to do it on the client side, you can use the ValidatorEnable function.
ValidatorEnable(document.getElementById("<%= RequiredFieldValidator.ClientID %>"), false);
(Note that I have never actually tried this myself, but I have heard of it successfully being used to disable validators on the client side.)
As this thread says, you can use that function. So modify your method like below
function cbSearchOption_SelectedIndexChanged(sender, args) {
var x = document.getElementById('cbSearchOption').value
if (x == 'Date')
{
ValidatorEnable($get(‘<%=DateValidator1.ClientID %>’), true);
document.getElementById('test').style.visibility = 'visible';
}
else
{
ValidatorEnable($get(‘<%=DateValidator1.ClientID %>’), false);
document.getElementById('test').style.visibility = 'hidden';
}
}
I need my web page to open a window and enable a disabled button when a link or a button is clicked.
From what I've read on other posts on here, if I try and open a new window in Page_load most browsers will assume it's a pop-up and block it so I've been trying to do it client side with JS.
Currently, I'm trying it with a link declared like so:
Please click here to open the document.
This calls the following JS:
function OpenDoc()
{
<%= btnSubmit.ClientID %>.Visible = true;
Window.Open('GetDocument.aspx')
}
Unfortunately, instead of rending the JS as "btnSubmit.Visible = true" it comes out as "MainContent_btnSubmit.Visible = true" which doesn't work.
Assuming this is the best way of doing what I want, where am I going wrong?
You can't change visibility property through javascript but you can use the following code instead of it :
var control = document.getElementById('<%=btnSubmit.ClientID %>');
control.disabled = true;
In this case the button will be disabled and if you need to hide button not disableing it then use the following code :
var control = document.getElementById('<%=btnSubmit.ClientID %>');
control.style.display= "none";
Hope this is helpfull based on my understanding to your problem
I have a RadioButtonList with 2 items. I want a postback when any of the items is selected. I have added a confirm box for one item of RadioButtonList. But, when I click OK in the confirmbox, there is no postback and SelectedIndexChanged event is not getting fired.
AutoPostback property of RadioButtonList is set to true.
This is a code fragment from my Page_Load method:
RadioButtonOpenRestricted.Attributes.Add("AutoPostBack", "True");
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("AutoPostBack", "True");
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("OnClick", "javascript:return confirm('Are you sure?');");
Earlier, I had added confirm box for entire RadioButtonList and postback was working as expected. But I want the confirm box to be displayed only when user clicks on "Open Access" item.
Please help!
I tried a few things. The new code lines look like:
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("OnClick", "javascript:showConfirmBox(0,'" + RadioButtonOpenRestricted.ClientID + "')");
RadioButtonOpenRestricted.Items.FindByValue("Restricted Access").Attributes.Add("OnClick", "javascript:showConfirmBox(1,'" + RadioButtonOpenRestricted.ClientID + "')");
The javascript method is:
function showConfirmBox(i,id)
{
if(i==0)
{
if (confirm("Are you sure you want to provide Open Access? All existing individual permissions will be removed!")==true)
{
var ctrl1 = document.getElementById(id + "_0");
ctrl1.selected=true;
}
else
{
var ctrl2 = document.getElementById(id + "_1");
ctrl2.selected=true;
}
}
if(i==1)
{
var ctrl2 = document.getElementById(id + "_1");
ctrl2.selected=true;
}
}
The problem with this code is that it is treating both OK and Cancel as same. The confirm box is getting displayed but if-else part of the javascript method is not getting called. I tried using OnClientClick also...this doesnt even display the Confirmbox.
Help!!!
This is because your on click script does not play well with auto-post back script generated by the ASP.NET. A quick hack solution can be
RadioButtonOpenRestricted.AutoPostBack = true;
RadioButtonOpenRestricted.Items.FindByValue("Open Access").Attributes.Add("OnClick", "if (!confirm('Are you sure?')) return false;");
Although, this will still give you an issue when you cancel on your confirmation box (in such case, you have to add script to select the previous radio button again).
As such I am not a great fan of radio button list - you may consider alternate mechanism such as repeater with radio button in item template and having your own java-script for confirmation.
I think you want to use OnClientClick to show a "confirm" window.
I don't think you can have a javascript confirm window perform a postback, at least not the way your code is set up.
You should set the OnClientClick to show a confirm modal or window with an <asp:Button/> and have that button perform the postback your looking for.
Khushboo, it used to happen with me many times. The reason behind that was I was missing some closing tag somewhere in my aspx page. I used to copy my whole aspx page to some other text editor and paste all the elements one by one to my aspx page. It always solved my this problem. I am sure you must be missing some closing tag, please cross check all elements.
I have an anchor link like:<a id="linkOwner" runat="server"></a>
In my codebehind I am disabling it based on some condittions like:linkOwner.Disabled = true; But still the link is click-able.How to fix it?
If you use an ASP LinkButton control I think you can just disable it on the server side and it'll properly disable it on the client. Not positive on that though. Another method is to use javascript. In the past I have used jQuery to add a click event to the disabled anchor with a empty event that returns false. Something like:
function disabler(){ return false; }
$('#linkOwner').click(disabler);
//to reactive the link
$('#linkOwner').unbind('click', disabler);
The return false lets jQuery know not to bubble up the event.
There are two solutions:
Change the anchor tag to an <asp:HyperLink> then you can set the Enabled property as you see fit.
You need to add an attribute to the control as in
linkOwner.Attributes["disabled"] = "disabled";
Disable anchor button by calling javascript void function and call another doAction function which will hanle your condition.
HTML implementation:
some text
Javascript implementation:
function doAction() {
if ( condition here ) {
// do X
} else {
// do Y action
}
}