Which .NET controls don't use javascript to handle events? - asp.net

I noticed that the
asp:Button
for example will work without javascript enabled in the browser. However any other control with an "OnClick" or "OnServerClick" event must use the javascript_doPostback.
Are there any controls besides the Button that don't need to use javascript?
I want to know because I want to be able to style the Control however I want without it looking like a button, and I want it to still work without the user having javascript enabled.
Any suggestions?

I think the answer is none. The button submits the form (as buttons will do) but no other controls auto-submit a form without a client side event handler.
Note that this also applies to the Link button.

_doPostback is the heart of ASP.NET. If you don't want to require the use of Javascript then ASP.NET isn't the language for you.

Related

Can I have a modal dialog from asp.net gridview edit click?

I am wondering if it is possible to have a modal dialog (like JQuery) by clicking Edit button on a asp.net built in gridview control. If yes, can anymore point me out the brief process of how it could be done. Please see the picture below for clarification.
Thanks.
I see few ways to do that:
Using OnEditCommand property (assuming you are using <asp:EditCommandColumn to draw that edit link):
You can show popup using serverside handler (for instance, popup included into ajaxcontroltoolkit.dll which allows to show popup from serverside easily on page reload)
Another option:
Make your own column with edit link for each item. It can have OnClientClick handler which will open jQuery popup directly on client (but you will need to get row info for current line from server somehow: with your own ajax call or, suppose it will be better, using webservice with webmethod)
Second option could be modified: instead of creating own column, you may add click even handler with that same jquery on default edit link with return false, so it will prevent form submition.
I never did something like this personally and even newer saw implementations of such thing, but I would select some option from those listed above. I do not think that there is some really simply, built in way of doing that.
UPD:
Here is an example of opening popup with own edit button and modalpopupextender from ajax control toolkit (similar like in my first option except that they are using own edit button, which I think could be easily replaced by default one and OnEditCommand even handler) :
http://www.c-sharpcorner.com/UploadFile/krishnasarala/edit-gridview-row-with-model-popup-extender-in-Asp-Net-ajax/

Detecting client-side DOM changes server-side in ASP.NET: Is It Possible?

I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).
This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?
You could also do this with traditional postbacks, it doesn't have to be ajax. The postbacks would be triggered by clicking your buttons which change which items are in which listboxes.
You could have a couple of hidden fields, say hdnHasSelectedChanged and hdnHasDeselectedChanged, and set those fields in your javascript code. Then, when a postback really happens, your code-behind can read those hidden fields to detect if changes occurred.

How can I trigger a server-side event from a client-side event?

Short version
All I need is that, in a ModalPopUp, when the DoubleClick event of a ListItem fires, the click event of my OK button should be executed.
Detail
I have a ModalPopUpExtender, which hosts a user control. The user control has an OK and a Cancel button. Along with that, it has a dynamic ListBox added to it. So far, I've considered the following possible solutions:
Use Ajax.Net. But, I cannot afford to have a WebMethod.
Use a ClientScriptCallBack. This will need a lot of JavaScript, since I have made almost every control dynamic.
Is there any other way apart from using an UpdatePanel?
Have a look at this way using __doPostback
calling a VB.net function from javascript

ASP.NET Button vs Linkbutton Enabled="false" behavior

Why do ASP.NET LinkButton controls with OnClientClick attribute and disabled by setting Enabled="false" still render onclick event handler in HTML while Button controls don't?
It seems counter-intuitive. Since anchors can't really be disabled in browsers, it makes more sense not to attach an onclick event (and href attribute) if it has been set disabled on server-side.
Well I would agree that it doesn't server much purpose, but without changing the way the linkbutton renders with one of the many methods built into asp.net there really isn't anything you can do about it. Unless you want to conditionally handle clicks in clientside code and check element attributes. This is just the way it is currently implemented so when you need the functionality of a button that can be disabled it is best to stay way from linkbuttons or anchors entirely.
This really has little to do with asp.net.
A hyperlink button still fires the onclick event even when disabled. Bottom line: baked into HTML. (An input tag, when disabled, does not fire.)
Click Me!

Do standard asp.net validators work with Ajax and update panel?

I am having issues with validators not firing (No expected error messages showing) when using Page.Validate() from code behind. The validators are placed inside an Ajax updatepanel.
It seems there are downloadable Ajax versions of the validators. I am not sure if I need these or if VS 2008 SP1 has them already. When the form is posted through a button, the validators work but they don't when I do a Page.Validate() on demand.
Yes, validators do work inside an UpdatePanel, but you need to use at least SP1 of ASP.NET 2.0. If you use SP1, you do not need and should not use the "ajax version" of the validators.
More details on this subject are available here:
StackOverflow: ASP.NET Validators inside an UpdatePanel
I don't want to force an update. In certain situations, I want to validate some form elements when a user changes the value on some form element. When I user makes a change to say a radio button or a dropdownlist, an automatic postback happens. When the postback occurs, I want the validation controls to fire as if I hit the submit button.
These controls which cause a postback have 'causevalidation' turned on. Another test is in the event handler of the control which caused the postback, I have a Page.Validate().
The question is why a button postback fires the validation but not another control which caused a postback?
Maybe we can take it from the top. Can you answer these?
Are you using .NET 2.0 SP1 or greater?
Are your validator controls inside the UpdatePanel or outside?
Are you using your site with javascript disabled (very unlikely)?
Note that your validators MUST be inside an updated UpdatePanel for them to display the error messages. If they are not in an updated UpdatePanel, the validators cannot change their appearance on the browser.
Did you call Update on your updatepanel?
They were included in a update for .Net framework a while ago, so yes, you have them in VS2008 SP1. I've found a problem where the server side method for CustomValidators fires twice with no "evil" effect, but otherwise they work ok.
As for the specific problem you're having, maybe the validators aren't inside the updatepanel, or some other panel ends up being refreshed by whatever control posted instead of the one that you want? Or even some ValidationGroups are defined somewhere and only these end up being validated? It's very hard to say without seeing code.
But making sure your validators are shown is easy: MyUpdatePanel.Update() will force the refresh.
I ended up using a single custom validator and doing my own validations in code behind and setting the custom validator's error message. This way I had more flexibility and it worked.
Using Ajax, it feels like client side validation.

Resources