943,776 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 7210
  • ASP.NET RSS
Jan 14th, 2009
0

Radiobuttonlist event doesn't fire..

Expand Post »
Hi I am trying to fire a javascript function from my .net radiobuttonlist but it does not fire. How do I fix this:

asp.net Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. this.rbl_NumberType.Attributes.Add("OnSelectedIndexChanged", "return NumberTypeChanged();");
  4. }
  5. ...
  6. function NumberTypeChanged()
  7. {
  8. alert("KJJK");
  9. }
  10. ...
  11. <asp:RadioButtonList ID="rbl_NumberType" runat="server">
  12. <asp:ListItem Value="0" Selected="True">Somnething1</asp:ListItem>
  13. <asp:ListItem Value="1">Somerthing2</asp:ListItem>
  14. </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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sniper1983 is offline Offline
30 posts
since Nov 2007
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

why dont you use onclientclick attribute instead of coding it?
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
sniper1983 is offline Offline
30 posts
since Nov 2007
Jan 14th, 2009
1

Re: Radiobuttonlist event doesn't fire..

asp.net Syntax (Toggle Plain Text)
  1. <asp:RadioButtonList ID="RadioButtonList1" runat="server">
  2. <asp:ListItem Text="someText" Value="someValue" onclick="alert('something1')"></asp:ListItem>
  3. <asp:ListItem Text="someText2" Value="someValue2" onclick="alert('something2')"></asp:ListItem>
  4. </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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
sniper1983 is offline Offline
30 posts
since Nov 2007
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

Click to Expand / Collapse  Quote originally posted by sniper1983 ...
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?
Ok, you asked a good question, the answer is the following :
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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

mark this thread as solved if it worked for you, also i will be motivated to answer your further questions if you add to my reputation
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jan 14th, 2009
0

Re: Radiobuttonlist event doesn't fire..

Arh.. I see.. That makes sence now. Thanks a lot

And ofcause.. Sorry that I forgot to do that..
Reputation Points: 10
Solved Threads: 0
Light Poster
sniper1983 is offline Offline
30 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to check errors while developing website online.
Next Thread in ASP.NET Forum Timeline: Search users(string) in XML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC