| | |
Radiobuttonlist event doesn't fire..
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
Hi I am trying to fire a javascript function from my .net radiobuttonlist but it does not fire. How do I fix this:
If I replaces OnSelectedIndexChanged in the eventhandler to onClick it fires every time something is clicked but not on "OnSelectedIndexChanged".. What is wrong? onclick is not even an event in a radiobuttonlist but OnSelectedIndexChanged is..
asp.net Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { this.rbl_NumberType.Attributes.Add("OnSelectedIndexChanged", "return NumberTypeChanged();"); } ... function NumberTypeChanged() { alert("KJJK"); } ... <asp:RadioButtonList ID="rbl_NumberType" runat="server"> <asp:ListItem Value="0" Selected="True">Somnething1</asp:ListItem> <asp:ListItem Value="1">Somerthing2</asp:ListItem> </asp:RadioButtonList>
If I replaces OnSelectedIndexChanged in the eventhandler to onClick it fires every time something is clicked but not on "OnSelectedIndexChanged".. What is wrong? onclick is not even an event in a radiobuttonlist but OnSelectedIndexChanged is..
Last edited by peter_budo; Jan 14th, 2009 at 7:21 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
If I understand you right, then you're asking why I dont use the asp.net eventhandler, right? And the answer is that there is no reason to handle the data serverside when I can do it clientside. What I should use the data for is hiding fields and stuff like that. A second bonus is that I prevent the screen flickering while updating (Not using ajax because of a core 2.0 in production).
EDIT: I think I misunderstood what you ment. Can you give an example of what you ask?
EDIT: I think I misunderstood what you ment. Can you give an example of what you ask?
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
asp.net Syntax (Toggle Plain Text)
<asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Text="someText" Value="someValue" onclick="alert('something1')"></asp:ListItem> <asp:ListItem Text="someText2" Value="someValue2" onclick="alert('something2')"></asp:ListItem> </asp:RadioButtonList>
add this to your page you will see it opens a javascript alert box. your code is fine except for you should add javascript to the items not the container tag.
Last edited by peter_budo; Jan 14th, 2009 at 7:21 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
•
•
•
•
Thanks alot..That works like a charm.. Though, it is displayed as a warning in vs2008. It says the attribute onclick is not a valid attribute for the element ListItem. Can you explain why I can use it, and especially to js calls. Normally they require server-side events, doesn't they?
in asp.net, your web server controls are processed at server and only pure html tags are sent to the client's browser. If web server control does not define any attributes named "onclick" it usually means that it will be sent to server as it is. But if onclick is defined, it is processed in the server and modified by it. For such cases there is usually "onclientclick" attribute that you can use for client-side functionality.
Due to lack of freedom of speech, i no longer post on this website.
![]() |
Similar Threads
- PostBackUrl (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: How to check errors while developing website online.
- Next Thread: Search users(string) in XML
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class click commonfunctions compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol expose findcontrol flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings rotatepage save search security serializesmo.table sessionvariables silverlight smartcard sql sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml youareanotmemberofthedebuggerusers






That works like a charm.. Though, it is displayed as a warning in vs2008. It says the attribute onclick is not a valid attribute for the element ListItem. Can you explain why I can use it, and especially to js calls. Normally they require server-side events, doesn't they? 