Prevent page refresh when button click without using UpdatePanel in asp.net - asp.net

How i can prevent page refresh when button click without using UpdatePanel in asp.net ?
Thanks in advance,

use OnClientClick="return false;
<asp:button ID="btnAdd" runat="server" text="Button" OnClientClick="return false;" />

I know you said you don't want to use an UpdatePanel, but this might work with your tabs, though I'm not completely sure. From what I've seen, you can create a "dummy" UpdatePanel that just holds your AsyncPostBackTriggers, then match them to your control handlers. I just ran across something like this:
<asp:UpdatePanel ID="upnlAsync" runat="server" >
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSave" EventName ="Click" />
<asp:AsyncPostBackTrigger ControlID="btnSave1" EventName ="Click" />
<asp:AsyncPostBackTrigger ControlID = "btnBackgroundTasks" EventName ="Click" />
<asp:AsyncPostBackTrigger ControlID = "btnReSubmit" EventName ="Click" />
<asp:AsyncPostBackTrigger ControlID = "btnSubmit" EventName ="Click" />
</Triggers>
</asp:UpdatePanel>
It is matched up with button controls, but they are not in an UpdatePanel themselves. When the Click handler is called in the code behind, the subroutine gets called, but the page doesn't refresh. I realize that this isn't really how the triggers are intended to be used, but it seems to work for my situation. Maybe it will work for yours.

Related

RowIndex attribute of templated field inside update panel

I want my templated buttons to have an update panel around it, but it messes up my rowindex attribute for the control. I tried to get the parent of the container but it says displayindex is not a property
<ItemTemplate>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="IBRemove" EventName="click" />
</Triggers>
<ContentTemplate>
<asp:ImageButton ID="IBRemove" runat="server" RowIndex="<%# Contanier.Parent.Displayindex %>" OnClick="IBRemove_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
The Link that VDWWD commented worked fine and it makes more sense to wrap the entire gridview in the update panel.
I was looking for this though:
RowIndex="<%# (DirectCast(Container, IDataItemContainer)).DisplayIndex %>"

Autopostback not updating updatePanels in IE6

having an issue supporting IE6 (meh)..
I have an update panel that is triggered by radio buttons. Its pretty straightforward.. show a form if one button it clicked, or another form if another button is clicked. In IE 7, 8, Firefox, etc. this works fine.
In IE6, the radiobutton selection doesnt update the form. If I make a selection, then click the submit button, when the page reloads it will be in it's desired state (meaning the correct form will show). So it's almost like the AutoPostback isnt firing to update the page.
Has anyone encountered this issue? Thanks In Advance..
Here's a shortened sample of what Im running into:
<asp:UpdatePanel ID="updrdoBuyingFor" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoBuyingFor" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:RadioButtonList ID="rdoBuyingFor" runat="server" AutoPostBack="true" >
<asp:ListItem Text="I am buying for someone else" Value="1" />
<asp:ListItem Text="It's for me" Value="2" />
</asp:RadioButtonList>
</ContentTemplate>
<asp:UpdatePanel ID="updMyInfo" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlMyInfo_Country" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="imgBtnContinue" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="rdoBuyingFor" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
...Code for Form A...
</ContentTemplate>
<asp:UpdatePanel ID="updFriendsInfo" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlMyInfo_Country" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="imgBtnContinue" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="rdoBuyingFor" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
...Code for Form B...
</ContentTemplate>
In response to #Pabuc below, Im setting the visible property of the table in "Code for Form A\B" to true or false depending on the radio button selection.
I've had the same problem with combobox.
What I did was instead of making the combobox visible, invisible, I made the tablerow visible invisible. I'm sure it'll work for you too. If you have more than 1 cells in your row, make the cell visible/invisible.
Let me know if it works.
Attributing this issue to the same question\answer I posted here: asp net 4 - autopostback doesnt fire in ie6

Refresh User Control without Refreshing the Page

I have a page and it has a button and a user control.
I want to refresh the user control without refreshing the page.
I know I cannot do it otherwise so what I did is wrapped my user control inside the Update Panel.
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
<asp:Button ID="btnAdd" runat="server" Text="Add name to list" OnClick="btnAdd_Click" /><br /><br />
<asp:UpdatePanel ID="upShowNames" runat="server">
<ContentTemplate>
<uc1:ShowNames ID="ucShowNames" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" />
</Triggers>
</asp:UpdatePanel>
But I still the control won't refresh.
I also tried calling the update panels. The Update() method by changing its UpdateMode to Conditional but that does not work either...
Does anyone know how can I do it?
Please change these 2 things
<asp:UpdatePanel ID="upShowNames" runat="server" UpdateMode="Conditional">
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click"/>
You missed the EventName on the postback trigger, once you add that, it should work :-)

Asp.net Response.Redirect Error

My team and I are working on a portal applicaiton. When a user requests a page, we get a page object (contianing permissions, actual file to use and what not). We then do a Response.Redirect to "~/Default.aspx".
The crazy thing is that when the code to validate access and what not is called from a button click event from within an ajax update panel, response.redirect is pasting a "&f2" or a "/" into the url. So rather than http://localhost/Default.aspx, the webbrowser is being redirected to http://localhost/%f2Default.aspx, and is subsequently returning a 404 error.
HttpContext.Current.Response.Redirect("~/Default.aspx", false);
Anyone have an idea of why this would occur? And it only happens when the click event fires inside an update panel.
It sounds like it is escaping the URL. Can you call a method on the code that is generating the URL to decode it before output?
The solution is to set up the update panel like this:
<asp:UpdatePanel ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlNewAddressCountry" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlAddressState" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlNewAddressCity" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlNewAddressPostalCode" EventName="SelectedIndexChanged" />
<asp:PostBackTrigger ControlID="btnCustomerAddressEditCancel" />
</Triggers>
...
<td colspan="2">
<asp:Button ID="btnCustomerAddressEditSave" runat="server" OnClick="CustomerAddressEditSave_Click"
Text="Save" />
<asp:Button ID="btnCustomerAddressEditCancel" runat="server" CausesValidation="false" OnClick="CustomerAddressEditCancel_Click"
Text="Cancel" />
<asp:Button ID="btnCustomerAddressEditDelete" runat="server" OnClick="CustomerAddressEditDelete_Click" OnClientClick="return confirm('Are you sure you want to delete this record?');"
Text="Delete" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

AsyncPostBackTrigger isn't working with simultaneous update calls

I have a page with some UpdatePanels, each one with its own button to update it. Since the update routines can take some time, I thought making them Asynchronous would help loading the page step by step.
But doing so, when I fire programatically the update routine of each panel, I get only the last UpdatePanel updated.
Here is an example of the code, with two UpdatePanels. There is the requirement that the update routine have to be fired on clientside pageLoad function.
Is it a bug or am I missing something in the code?
Thanks =)
<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="Text1" runat="server" />
<asp:Button ID="Button1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="Panel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="Text2" runat="server" />
<asp:Button ID="Button2" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
And the client-side code:
function pageLoad()
{
$('#Button1').click();
$('#Button2').click();
}
Here is why:
By default, when a page makes multiple
asynchronous postbacks at the same
time, the postback made most recently
takes precedence.
http://www.asp.net/ajax/documentation/live/tutorials/ExclusiveAsyncPostback.aspx
Here is a solution:
Handling Multiple Asynchronous Postbacks

Resources