I am not sure whether I have understood your meaning. Assuming that you don't want to refresh the CheckBox when you click the Button, you can use
UpdatePanel control. However, you need to modify your code and move the CheckBox out of the UpdatePanel. In order to help you understand, I have written a demo below:
Please test it locally. When you click the Button and CheckBox, you will find the difference.
Note that when you set AutoPostBack="true", the event CheckBox1_CheckedChanged will occur and make a postback. When you set it false, it willn't do a postback. In addition, I would suggest you to use IE Develop Tools to debug step by step.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Catherine Sh...
All-Star
23372 Points
2490 Posts
Microsoft
Re: avoid refresh in a button click event
Feb 24, 2012 02:41 AM|LINK
Hi raja_durai1,
I am not sure whether I have understood your meaning. Assuming that you don't want to refresh the CheckBox when you click the Button, you can use UpdatePanel control. However, you need to modify your code and move the CheckBox out of the UpdatePanel. In order to help you understand, I have written a demo below:
In the .aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional"> <ContentTemplate> <asp:Label runat="server" id="DateTimeLabel1" /> <asp:Button runat="server" id="UpdateButton1" onclick="UpdateButton_Click" text="Update" /> </ContentTemplate> </asp:UpdatePanel> <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" oncheckedchanged="CheckBox1_CheckedChanged" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>In the code behind
protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = DateTime.Now.ToString(); } protected void UpdateButton_Click(object sender, EventArgs e) { DateTimeLabel1.Text = DateTime.Now.ToString(); } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { }Please test it locally. When you click the Button and CheckBox, you will find the difference.
Note that when you set AutoPostBack="true", the event CheckBox1_CheckedChanged will occur and make a postback. When you set it false, it willn't do a postback. In addition, I would suggest you to use IE Develop Tools to debug step by step.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
rossisdead2
Participant
1313 Points
300 Posts
Re: avoid refresh in a button click event
Feb 24, 2012 10:08 PM|LINK
The page will postback regardless of whether or not the button has an OnClick handler attached to it.