Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Stephen Hewison 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.

you can use onchange event that is client side event you can call javascript and check whatever

C#
function Checking() {
           alert('test')
           }




ASP.NET
<asp:radiobutton id="RadioButton1" runat="server" onchange="Checking()" xmlns:asp="#unknown" />
 
Share this answer
 
v2
First there should not autopostback="true" in your Radio button
ASP.NET
<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:
JavaScript
$(document).ready(function () {
           $('#Radio1').change(function () {
              //do something here
           });
           $('#Radio2').change(function () {
             //do some more stuff here
           });
       });
 
Share this answer
 
v2
Go this you will get more info:

Click Here
 
Share this answer
 
Hello friend go on this website................
[^][^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900