IFrame not to be reloaded on ASP.NET postback - asp.net

I have an IFrame on my asp.net page along with other user controls such as radiobutton, textbox, etc.
A problem that I am facing right now is that when I click on a radio button, it triggers the postback which make my IFrame reload as well.
Is there any way I could make the IFrame not to reload on the postback?
Thanks.

Set AutoPostBack="false" porperty of all asp.net controls or use update panel <asp:RadioButton Text="text" AutoPostBack="false" runat="server" />

Related

on every postback page opens in a new tab

I have a weird problem in my page. I have a button called Print. I wanted report should come in a new tab, so i wrote some javascript on button's onClientClick. Which works great with no problem at all.
But problem starts now when user comes back on original page again, now here i have several controls which cause postback. Say for example its a dropdownlist. so whenever user changes dropdown item it causes postback which is fine but everytime it opens a new tab on every postback.
hope I am clear in question...
Any help??
Here is a code:
<asp:Button ID="btnshow" runat="server" Text="Show" Font-Bold="true" ForeColor="Black" Width="90px" OnClick="btnshow_Click" OnClientClick ="document.forms[0].target = '_blank';"/>
The issue is document.forms[0].target='_blank' is setting the target on the form not the individual button so a postback triggered by any control will open in a new tab.
You should use a HyperLink control instead of the Button control. The HyperLink control has a Target property which allows you to specify how the link should be opened.
Below is an example taken from the HyperLink documentation. This will render an anchor tag with target="_blank".
<asp:HyperLink ID="lnkPrint" NavigateUrl="http://www.microsoft.com" Text="Print" Target="_blank" runat="server" />

Row click in GridView when ViewState is disabled

We are using classic ASP.NET 4. There is a GridView that's causing problems because there is no paging and the ViewState is too large. So, disabling the view state via EnableViewState="False" seemed to solve the problem with the viewstate size, but now I can no longer click on rows. The page refreshes, but the call-back corresponding to CommandName="OpenItem" is not firing.
<ItemTemplate>
<asp:ImageButton
ID="Id"
runat="server"
CommandName="OpenItem"
/>
</ItemTemplate>
I tried adding OnClick="ClickHandler" to the ImageButton, but that didn't work either -- the OnClick callback is not firing.
Is there any way, other than adding paging, to have the ViewState disabled and handle clicks on GridView rows?
Thanks.

Asp.Net multiple submit buttons, enter submits only the first

I have a few submit buttons in my ASP.NET page. Everything works fine, but when a user hits enter button always the first submit button works. I want to fire each submit button with corresponding fields but cannot have multiple forms. Is it possible to group them without using forms?
You don't need forms, just wrap the related controls in their own panels and use the Panel.DefaultButton property.
Use the DefaultButton property to indicate which button gets clicked
when the Panel control has focus and the user presses the ENTER key.
The DefaultButton can be set to the identifier for a Button control or
any control that implements the IButtonControl interface except a
LinkButton control.
Please use DefaultButton property like this
<asp:Panel runat="server" DefaultButton="bt1">
<asp:TextBox runat="server" />
<asp:Button id="bt1" Text="Default" runat="server" />
</asp:Panel>
Please refer here :- ASP.NET DefaultButton Property

OnTextChanged loses focus when AutoPostBack is true

I have a ASP.Net webform that has several textboxes. Some of the textboxes have an OnTextChanged event with AutoPostBack set to true.
When the user enters some text and leaves the textbox, I want some code to run. This part works fine.
The problem is that if a user enters some text, then clicks or tabs to another textbox, the OnTextChanged of the current textbox event fires fine but the textbox that the user clicked on does not keep focus. This causes problems because the user thinks they are on the next textbox but they aren't. And no object seems to have the focus.
Is there anything that can be done to make the next object keep focus while the OnTextChanged event of the current textbox fires?
One option is to use <asp:UpdatePanel> Control.
Facts about using it:
The postback request would be made via AJAX.
It would not recreate the whole page HTML.
When the UpdatePanel updates, it replaces the DIV innerHTML, that would make the textbox lose focus (bad point).
To maintain the focus, you would have to avoid the UpdatePanel from updating when the textbox posts back.
You can avoid the update by setting the UpdateMode and ChildrenAsTriggers properties.
Here is an example:
<asp:UpdatePanel ID="uppTextboxes" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:TextBox ID="txb1" runat="server" AutoPostBack="true" OnTextChanged="txb1_OnTextChanged" />
<asp:TextBox ID="txb2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Since the whole page is recreated on postback on serverside and the browser will recreate all html on clientside, you have to tell ASP.NET that your TextBox needs focus.
Use Page.SetFocus:
Page.SetFocus(IdOfControl);
However, i would prefer not to postback at all if i can. Can't you use a button that the user has to click after he has entered all necessary data?

ASP.NET Textbox: OnTextChange jumps to top of page because of autopostback

I'm using the OnTextChange event on a textbox on an ASP.NET page. To have this working I have to put 'AutoPostBack=true'.
The problem is that the textbox is on the bottom of the page, and when the text changes it has to fill another textbox. This is working fine but when the event triggers the page refreshes and jumps to the top of the page, so I always have to scroll down again to see it. (Due to the autopostback)
Is there anything I can do to prevent it to jump to the top of the page?
Use UpdatePanel and put that text box for which u r triggering OnTextChange event in of from ajax extensions and dont forget to include scriptmanager at top of the page
the code goes like this
<asp:UpdatePanel>
<content>
<asp:TextBox runat="server" AutoPostBack="true" OnTextChanged="textbox_textchanged">
</asp:TextBox>
</content>
</asp:UpdatePanel>
In the page_load event write below code.
this.MaintainScrollPositionOnPostBack = true;

Resources