__doPostBack won't work if JavaScript is disabled - dopostback

If the JavaScript of browser is disabled then __dopostback won't work. I am looking for the alternative to this because I have radio button and drop down list controls in web page that should fire postback even if JS is disabled.

Autopostback cannot be made to work without javascript, as a workaround, you could put a button next to the radio button/drop down list only for those users with javascript disabled to manually trigger a post back:
<noscript><asp:Button ID="uxManualPostback" runat="server" Text="Go" /></noscript>
In the code behind (server side) you would then hook up the button's click event to do same thing the autopostback of the radio button/drop down list would have done.

Related

Disable/Enable a button inside a panel on an ascx control in a vb.net website from codebehind not JQuery

In my website I have a vb.net ascx control which contains a number of textboxes and a button. When the button is clicked I want to disable it, then perform some actions using the values of the textboxes, and then enable the button again. The problem i'm having is that i cannot disable the button.
The ascx control contains an asp:Panel, and inside that is an asp:UpdatePanel which contains the textboxes and the button. Could the asp:Panel or the asp:UpdatePanel be preventing the button being disabled? I can empty the textboxes without a problem, but nothing seems to work on the button.
I've tried
btnButton.Enabled = False
and
btnButton.Attributes.Add("disabled")
but they have no effect. Neither does setting the Visible property to false. The UpdateMode on the Asp:UpdatePanel is set to Always. I'm not too familiar with Asp:Panels or Asp:UpdatePanels so i'm guessing it's something to do with them. Does anyone know the correct way to do this?
After some more research I came across the solution. I just needed to add some attributes to my button like this:
<asp:Button ... OnClientClick="this.disabled=true;" UseSubmitBehavior="false" />
This will disable the button when it is clicked, but still allows the codebehind to run as well. When the codebehind has completed the button will be enabled again.

asp.net detect DropDownList.SelectedIndexChanged after Button Click (JS disabled)

I have a DropDownList which is connected to a TextBox. When the event SelectedIndexChanged is fired, the text in the Textbox changes. The content of the textbox can also be changed by user input. At the end of the page the user has to submit the data (button).
When javascript is enabled everything works fine, but I have also users where javascript is disabled.
Without javascript the SelectedIndexChanged event of the DropDownList gets called after the Button-Click (before the Click-Event of the button is processed). The user input to the textbox gets overwritten by the SelectedIndexChanged event.
How can I detect in Code behind if the SelectedIndexChanged event was triggerd by the button click? How can I get the text of the textbox changed by the user?
EDIT:
Can I use the property IsPostBackEventControlRegistered? This always seems to be true when I click the button, but is false in SelectedIndexChanged event.
Well, it IS possible, but not easy. You would essentially need to track whether javascript is enabled by using a hidden field, do something like:
<asp:HiddenField ID="JSEnabled" runat="server" ClientIDMode="Status" Value="F" />
<script type="text/javascript">
function checkForJavaScript() {
$("#JSEnabled").val("T");
}
</script>
You call this script from window.onload or jquery.ready event, whatever JS option you like, and this can tell you whether you have JS enabled to do the selectedindexchanged event, or if a button triggered it because JS wasn't enabled. To tell whether the button was clicked and caused the postback, you can check the:
Request.Form.Get("__EVENTTARGET")
Field and see if the ID matches the UniqueID of the button. Every control in ASP.NET sets its ID (usually, but not always, for certain reasons) here. Although, I'm not sure, you may have to set UseSubmitBehavior="False" for that to happen. A hidden field can be manipulated, so it's not fullproof.
The question you should ask is do you really need that complexity?

Clicking on linkbutton, don't want validators to fire

I have a profile page with a bunch of textboxes and validators. The validation works fine right now. My issue is that I have added a couple of link buttons that go to different pages. When I click on a linkbutton the validators fire, which I don't want. I just want to go to the next page.
I tried disbling the validators in the linkbutton click event but it didn't work. How do I stop the validators firing?
Thanks
Simply set the CausesValidation atrribute to false on the linkbuttons in the markup:
CausesValidation="false"
LinkButton.CausesValidation Property

Disable LinkButton when OnClick Event Fires

I have an asp:LinkButton as follows:
<asp:LinkButton ID="LinkButtonNewServicesCategory" runat="server"
OnClientClick="this.disabled=true;return false;"
style="float:left;margin-right:5px;" CausesValidation="False">new services category</asp:LinkButton>
The intent is that when the LinkButton is clicked, it disables itself and returns false to prevent the postback (this control is used as a trigger for an animation).
The behavior I'm experiencing is that the LinkButton correctly triggers the animation and returns false, but does not disable itself.
It's inside an updatepanel, but I'm sure that no postback is occurring.
Why doesn't this.disabled=true work?
I'm not familiar with the way asp.net interacts with js but to disable an element with javascript use:
this.disabled=disabled; // not disabled=true
Then, to enable it again, remove the disabled attribute.

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!

Resources