Click here to Skip to main content
15,999,253 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
I have used radiobuttonlist in my asp.net page. Whenever I select any list item, the page refresh every time. How can page refresh be avoided?
Posted

1.The property AutoPostBack when is set on true will generate postback of your page, and postabck means that the entire page is send to the web server.

2.The solution to notify the server that your radiobuttonlist was changes is to change this AutoPostBack property on false and then to use Javascript on your page that will invoke by using AJAX your code from your web server and in this way only a partial zone of your page will be re-rendered.
 
Share this answer
 
Use updatepanel control, try the following example:
1. On the aspx page:
XML
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager" runat="Server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="updatePanel1" runat="server">
    <ContentTemplate>
        Light Switch&nbsp;&nbsp;
        <asp:RadioButton ID="lightOn" AutoPostBack="true" runat="server"
            GroupName="switch" Text="Turn On" OnCheckedChanged="lightOn_CheckedChanged" />
        &nbsp;&nbsp;&nbsp;
        <asp:RadioButton ID="lightOff" AutoPostBack="true" runat="server"
            GroupName="switch" Text="Turn Off" OnCheckedChanged="lightOff_CheckedChanged" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

2. On the code behind:
C#
protected void lightOn_CheckedChanged(object sender, EventArgs e)
{
    Label1.Text = "Light has been turned on";
}
protected void lightOff_CheckedChanged(object sender, EventArgs e)
{
    Label1.Text = "Light has been turned off";
}

Find out more Introduction to the UpdatePanel Control[^]
 
Share this answer
 
v2
C#
use update panel control and put the radio button list control inside the panel

and use a script manager and set the partialRendering property of script manager=true
 
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