How to disable RadNumeric TextBox, but with working spinbuttons? - asp.net

I have a Telerik RadNumericTextBox that has spinbuttons to increment/decrement the value. I want to prevent the user from entering their own input and to only use the spinbuttons. When I try to disable the textBox or make it readonly, the buttons are disabled as well. Is it possible to keep the buttons functional and make the textBox only for display?
I have certain attributes on this control that I need so continuing to use a Telerk RadNumericTextBox would be more convenient than using other controls.

$telerik.$($find("Numeric1").get_element())
.focusin(function(){ this.readOnly = true; })
.focusout(function(){ this.readOnly = false; });
Working on this page http://demos.telerik.com/aspnet-ajax/input/examples/radnumerictextbox/firstlook/defaultcs.aspx

Related

Disabling the asp.net link button n radios using Jquery

How to disable the asp.net Link buttons and asp.net radio buttons.
I have used
to enable
$("#sLbtnFirst").attr("disabled", "");
to disable
$("#sLbtnFirst").attr("disabled", "disabled");
but i'm able to click the buttons they are just greying
In .NET radio buttons, the attribute that specifies whether they're clickable is called "enabled", not "disabled".
But, at client-side they are rendered as html input tags which do contain the attribute "disabled" so to disable them you would want to use:
$("#sRbtnFirst").attr("disabled", "disabled");
To enable:
$("#sRbtnFirst").removeAttr("disabled");
EDIT: I've tried your jQuery myself in a .NET app and it seems to grey out the radio buttons fine (and prevent clicking). The LinkButton's a different story though.
You'll also need to remove the "href" attribute to prevent it from performing an action on click. So:
$("#sLbtnFirst").attr("disabled", "disabled");
$("#sLbtnFirst").removeAttr("href");
That should disable the LinkButton.
Also, remember that your IDs will change when they are rendered in the form so they won't be what they are when you view your aspx page in Visual Studio. .NET will change them into something like:
#ct100_sLbtnFirst
Link buttons render as anchor tags (<a href=) and the disabled attribute is not defined for this tag. As far as radio buttons are concerned you could apply the disabled attribute to them, they will grey out and their value won't be sent when you post the form.
To enable/disable linkbutton, try this:
//disabling
document.getElementById('sLbtnFirst').onclick = function() {return false;}
//enabling
document.getElementById('sLbtnFirst').onclick = function() {return true;}
You should use:
$("#sRbtnFirst").removeAttr("disabled");

Get access to ASP.Net CreateUserWizard buttons

I'm using a CreateUserWizard on my register page. The Sign Up button is part of a CustomNavigationTemplate.
I need to set the Sign Up button as the default button of a ASP:Panel, but can't do so since it's inside the template. I tried to do so, but I can't locate the Sign Up button using CreateUserWizard.FindControl, CreateUserWizard.WizardSteps(0).Controls(0).FindControl or other similar steps (this is a known issue with this control).
Any ideas on how I can expose this button, or set it as the panel's default button in some other way?
Here's how I finally did it:
Referencing the CreateWizard Button and assigning to Panel's Default Button:
Dim RegisterButton as Button = Ctype(CreateUserWizardStep1.CustomNavigationTemplateContainer.FindControl("RegisterButton"), Button)
RegisterPanel.DefaultButton = RegisterButton.ID 'Or RegisterButton.UniqueID
I wasn't able to use the above, because it was giving me the error "The DefaultButton of 'RegisterPanel' must be the ID of a control of type IButtonControl"
I finally created a dummy button called "RegisterButton" (same name as the register button inside the template) and hid it using CSS, and gave it's OnClick the 'real' register button's function call.
For the login section, I used this:
Page.Form.DefaultButton = LoginButton.UniqueID

Can Anyone Help me with this? Refresh update panel partially onclient side

i have a dynamically created gridview button that fires off a modal popup when clicked. I do this onclientside like so:
function openModal(btnId, v) {
deptdata(v);
// __doPostBack('<%=DropDownList1.ClientID %>', '');
btn = document.getElementById(btnId);
btn.click();
}
function deptdata(v) {
document.getElementById('<%=vendor.ClientID%>').value = v;
}
This is how the function is called in the code.
btnedit.OnClientClick = String.Format("openModal('{0}','" & GridView1.Rows(i).Cells(0).Text & "');return false;", hidden.ClientID)
I set the value of a hidden field(Vendor) but I need that value for what's in the modal popup. I have a dropdown list that depends on that newly set variable. The variable is set depending on what row was clicked. So i need to somehow just reload that popup. I have an Update Panel but I can't get that Panel to reload. I've tried __doPostback and it didn't help. any ideas how to update the panel or the dropdown in the panel using javascript?
It's not very clear from your description and the limited code you provide what it is exactly that you are trying to do and what is failing. However, the following might give you some ideas. If you provide more detail and code someone might be able to give you a better answer.
ScriptManager1.RegisterAsyncPostBackControl(Button1);
to trigger an update panel post back from js make sure you use UniqueID, not ClientID, thats a common gotcha that prevents the async postback from working.
__doPostBack("<%=Button1.UniqueID %>", "");
Personally, I have all but given up on UpdatePanels, I only use them in the most trivial cases. I prefer to have my js call an ASP.Net JSON webservice and have the on completed function render any needed changes to the html. It's more flexible, lighter and infinitely faster for pages with large grids or a lot of controls.

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn't do the "Ok". Instead I have to manually click on Ok to Submit. How can I do by pressing Enter on my Keyboard rather than Clicking on "Ok" button after selecting the value from dropdown list. I have set the SubmitBehavior to true.
Try the solution here: ASP.NET 2.0 - Enter Key - Default Submit Button.
Assuming you're talking about a web form:
I'm no ASP.NET guru, but the default behavior of an HTML form is to submit in this case. Common causes for this are the HTML form fields not being contained within the form element, or the submit button having a nonstandard javascript function fire instead of submitting proper.
I realize that's not an answer, but I hope it might help.
using jquery you can do something like this
$("#fieldName").keypress(function(event)
{
if (event.keyCode == 13)
{
return true;
}
else
{
return false;
}
});
See more here: http://docs.jquery.com/Events/keypress
Try setting Page.Form.DefaultButton = OkButton; in your code-behind.

Setting Focus with ASP.NET AJAX Control Toolkit

I'm using the AutoComplete control from the ASP.NET AJAX Control Toolkit and I'm experiencing an issue where the AutoComplete does not populate when I set the focus to the assigned textbox.
I've tried setting the focus in the Page_Load, Page_PreRender, and Page_Init events and the focus is set properly but the AutoComplete does not work. If I don't set the focus, everything works fine but I'd like to set it so the users don't have that extra click.
Is there a special place I need to set the focus or something else I need to do to make this work? Thanks.
We had exactly the same problem. What we had to do is write a script at the bottom of the page that quickly blurs then refocuses to the textbox. You can have a look at the (terribly hacky) solution here: http://www.drive.com.au
The textbox id is MainSearchBox_SearchTextBox. Have a look at about line 586 & you can see where I'm wiring up all the events (I'm actually using prototype for this bit.
Basically on the focus event of the textbox I set a global var called textBoxHasFocus to true and on the blur event I set it to false. The on the load event of the page I call this script:
if (textBoxHasFocus) {
$get("MainSearchBox_SearchTextBox").blur();
$get("MainSearchBox_SearchTextBox").focus();
}
This resets the textbox. It's really dodgy, but it's the only solution I could find
this is waste , its simple
this is what you need to do
controlId.focus(); in C#
controlID.focus() in VB
place this in page load or button_click section
eg. panel1.focus(); if panel1 has model popup extender attached to it, then we put this code in page load section
How are you setting focus? I haven't tried the specific scenario you've suggested, but here's how I set focus to my controls:
Public Sub SetFocus(ByVal ctrl As Control)
Dim sb As New System.Text.StringBuilder
Dim p As Control
p = ctrl.Parent
While (Not (p.GetType() Is GetType(System.Web.UI.HtmlControls.HtmlForm)))
p = p.Parent
End While
With sb
.Append("<script language='JavaScript'>")
.Append("function SetFocus()")
.Append("{")
.Append("document.")
.Append(p.ClientID)
.Append("['")
.Append(ctrl.UniqueID)
.Append("'].focus();")
.Append("}")
.Append("window.onload = SetFocus;")
.Append("")
.Append("</script")
.Append(">")
End With
ctrl.Page.RegisterClientScriptBlock("SetFocus", sb.ToString())
End Sub
So, I'm not sure what method you're using, but if it's different than mine, give that a shot and see if you still have a problem or not.
What I normally do is register a clientside script to run the below setFocusTimeout method from my codebehind method. When this runs, it waits some small amount of time and then calls the method that actually sets focus (setFocus). It's terribly hackish, but it seems you have to go a route like this to stop AJAX from stealing your focus.
function setFocusTimeout(controlID) {
focusControlID = controlID;
setTimeout("setFocus(focusControlID)", 100);
}
function setFocus() {
document.getElementById(focusControlID).focus();
}
I found the answers from Glenn Slaven and from Kris/Alex to get me closer to a solution to my particular problem with setting focus on an ASP.NET TextBox control that had an AutoCompleteExtender attached. The document.getElementById(focusControlID).focus() kept throwing a javascript error that implied document.getElementById was returning a null object. The focusControlID variable was returning the correct runtime ClientID value for the TextBox control. But for whatever reason, the document.getElementById function didn't like it.
My solution was to throw jQuery into the mix, as I was already using it to paint the background of any control that had focus, plus forcing the Enter key to tab through the form instead of firing a postback.
My setFocus function ended up looking like this:
function setFocus(focusControlID) {
$('#' + focusControlID).blur();
$('#' + focusControlID).focus();
}
This got rid of the javascript runtime error, put focus on the desired TextBox control, and placed the cursor within the control as well. Without first blurring then focusing, the control would be highlighted as if it had focus, but the cursor would not be sitting in the control yet. The user would still have to click inside the control to begin editing, which would be an UX annoyance.
I also had to increase the timeout from 100 to 300. Your mileage my vary...
I agree with everyone that this is a hack. But from the end-user's perspective, they don't see this code. The hack for them is if they have to manually click inside the control instead of just being automatically placed inside the control already and typing the first few letters to trigger the auto lookup functionality. So, hats off to all who provided their hacks.
I hope this is helpful to someone else.

Resources