Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
I want to validate texbox on radio button on change event but my page is getting post back at the time of radio button onchange event
so, how can i prevent page post back
Please help
 
rajp11
Posted 18-May-12 0:50am
rajsp11307
Comments
Stephen Hewison 2 at 18-May-12 7:03am
   
Could you post the ASPX for the radio button? My guess is that you've tried writing javascript into the onchange attribute. The onchange attribute for the server side control creates a postback. You need to do something like this in you server side code.
 
ctlRadioButton.Attributes.Add("onchange", "alert('test');");
 
This will write the alert('test'); command to the HTML rendering as a client event.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can use onchange event that is client side event you can call javascript and check whatever
 
function Checking() {
           alert('test')
           }
 

 
 <asp:radiobutton id="RadioButton1" runat="server" onchange="Checking()" xmlns:asp="#unknown" />
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

First there should not autopostback="true" in your Radio button
 <tr>
                                        <td>
                                            <asp:radiobutton id="Radio1" checked="true" runat="server" text="Text" groupname="rd" xmlns:asp="#unknown" />
                                        </td>
                                        <td>
                                            <asp:radiobutton id="Radio2" runat="server" text="Image" groupname="rd" xmlns:asp="#unknown" />
                                        </td>
                                    </tr>
then using jQuery it will get like this:
 $(document).ready(function () { 
            $('#Radio1').change(function () {
               //do something here
            });
            $('#Radio2').change(function () {
              //do some more stuff here
            });
        });
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Go this you will get more info:
 
Click Here
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hello friend go on this website................
[^][^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 339
1 Nirav Prabtani 248
2 OriginalGriff 234
3 _Amy 165
4 Maciej Los 145
0 OriginalGriff 7,744
1 Sergey Alexandrovich Kryukov 6,956
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 19 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100