Adding on change event to dropdownlist declared with a select class - asp.net

Issue adding on change event to a control.
I currently have a page that uses this in the aspx page to declare a dropdownlist
<select class="dropdownPhase" />
I am trying to add a on change event to the above dropdownlist something like what i did on another page. the problem is i cannot change it to be declared like a normal dropdownlist is it possible to add the onchange event?
<asp:DropDownList ID="dropdownPhase" onchange="ApplicationRecording.prototype.onPhaseChange1(this,$(this).closest('tr'));" />

You can add the client-side event to the DropDownList in code:
dropdownPhase.Attributes["onChange"] = "someJavaScriptFunction();";
You might have to set AutoPostBack to False.
Hope this helps.

Related

Disabling an ASP.net textbox without actually disabling it?

Within an ASP.Net application I have, there is a textbox that gets a date from a CalendarExtender. When the textbox is populated it checks that date with another date on the form and displays a modalpopupextender popup if the dates are wrong. However, I DO NOT want to allow user input into this textbox, so when I set the ReadOnly field to false and tried Enabled to false, it doesn't allow manual entry however it ALSO disabled the postback and will not call the TextChanged event to fire the modalpopupextender.
So is there a way to disable manual entry and not set it to ReadOnly?
I figured it out, simply enter onkeypress="return false;" within the HTML tag
Try this
<asp:textbox id="txt1" onfocus="blur()" runat="server"/>
this worked for me.
Add the below properties in the tag of textbox
onkeydown="return false" onpaste="return false"
ex:
<asp:TextBox ID="TillDate_TextBox" runat="server" onkeydown="return false" onpaste="return false"></asp:TextBox>
the first property block typing in textbox and the second property block pasting in it
I'm not familiar with the exact components you are using, however the usual way to accomplish things like this is the following. Have selecting the date on the calendar modify the value of a hidden form field. This will restrict the user from editing the value directly. Then create another element like a div or a span, and use javascript to update the span/div to the value selected on the calendar.

How to enable html select post back apsx page when selection changed?

With asp.NET control dropdownlist, there is a property AutoPostBack, if it is set "True", the whole page will be posted back.
If the aspx page include a html element "select" like:
<select id="list" name="list" runat="server"
DataTextField="Name" DataValueField="ID" ></select>
and it data is filled by code-behind.
Question is: how to allow this Select have AutoPostBack function too?
The DropDownList approach adds a __doPostBack('selectelementname', 'commandname'); call to the onchange event. When you change the value, this then proceeds to post back to the server, and then the ASP.NET control processes the postback data in LoadPostData method.
HTH.
You can't apply Auto post back property for html select control.To invoke function writen inside c# code page(serverside),you need to use webservice. You can call javascript function(client side) on 'onchange' event of html select control.

When I click a button on the form...my code never reaches it's onclick event

I have a dropdownlist and a textbox with a button on a form. When a button is clicked it does not go to my onclick even in the code but it goes to my dropdownlist's selectedIndexchanged event. How can I fix this?
I'm not a VB.net person but try changing your asp:button to this:
<asp:Button id="btnlookup" Height="24px" Text="LookUp" Width="60px"
OnClick="btnlookup_Click" runat="server"/>
Does your Page_Load have a call to changing the selected index or the items in the DropDownList outside of checking for postback?
Make sure the event handler is handling the correct control, or the button tag is referencing the correct method on it's onclick element.
If your dropdown list is not set to autopostback, and you change its value before clicking the button (and triggering a postback), then the dropdown's onchange event is supposed to fire.
...not that this explains why you click handler isn't firing.

How to get value in a textbox that is readonly

I have a textbox.In its onclick iam calling a javascript fn to call calendar.Texbox is readonly. Clicking on textbox calendar is coming and value is showing in textbox. But on clicking submit button where I have written code to save, there i am not getting value in textbox. What may be the reason for that?
I suspect that your text box has the disabled attribute instead of readonly which prevents it from posting its value to the server.
I had this problem too, there is a really simple workaround
Instead of making the textbox ReadOnly using properties option. Do it thru the code behind adding this code:
YourTextBox.Attributes.Add("readonly", "readonly");
You can get the value by using
Request.Form[YourTextBox.UniqueID]
I'm guessing the textbox is disabled so that people have to use the calendar control to enter a date? The textbox is just for showing the selected date?
If you want the textbox to stay readonly (i.e. disabled client-side), have a hidden input that has the value you want to handle on the server is the way to go probably. So add an additional input for to the page. Use
<asp:HiddenField ... runat="server" />
So the client-side code that updates your readonly textbox will also update your hidden input.
if readonly property is true, its not break your .cs call. you can use this as always:
here are your inputs:
<asp:TextBox ID="txtBraid" runat="server" Text="Im sooo readonly" ReadOnly="True"></asp:TextBox>
<asp:Label ID="lblBraid" runat="server" Text="Im gonna change, i promise"></asp:Label>
on .cs page put these to onClick function or something:
lblBraid.Text = txtBraid.Text;

Adding javascript to the OnBlur property of an ASP.NET text box control

Is there a way to specify some JavaScript to execute on the OnBlur event of an ASP.NET text box? It seems to me like if I add any event handlers to the TextBox object they will just cause postbacks to the server isntead of doing what I want. Basically, I just want to be able to have the textbox be rendered in this HTML:
<INPUT type="text" onblur="alert('1234')" />
Thanks!
Could also go for:
<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />
if you dont feel like setting it up in the codebehind.
Im guessing the reason why you end up with postbacks, must be because you have set AutoPostBack on the textbox to true. That makes the textbox postback when the client-side onchange event is triggered. Switch it to false, and it will act as a normal input-element.
In your codebehind, add this:
myTextBox.Attributes.Add("onblur","alert('1234');");

Resources