I am using IFrame in my ASP.NET pages. For the page that I am referencing in my IFrame, I have a gridview (I also have CommandField that referencing another asp.net page) and paging enabled.
I wanted to display a new page (outside of Iframe) when a user clicks on the commandfield in the gridview. In order to do that I set form's target to "_parent". This works fine (it open a new page outside of Iframe). Now, my problem is that when i click on the paging to go to next page in the gridview, it also opens the gridview outside of IFrame (which I dont want to happen). I want it to open within the Iframe.
Is there any way I could set the target as I needed?
Thanks.
Use some jQuery: (Just threw this idea together, not tested)
$("#myElement").click(function() {
if(window.location != window.parent.location)
{
// window is in iframe
$(this).attr("target", "_self");
}else{
$(this).attr("target", "_parent");
}
});
Related
I have a user control (toolbar). It is located in the master page and most pages in the project use this master page and therefore the toolbar user control. Print button in the toolbar control has to open print page in a new window. It is a hyperlink with target = '_blank'. In most of the pages it opens in a new window and in only one page it opens in the same window (which is wrong). This weird page has the same master page and hyperlink properties is the same during debugging.
Sounds strange, I would check the markup of that specific page where target="_blank" doesn't work and see if it contains any broken markup which could possibly cause that behavior. Maybe the attribute isn't read correctly on that page due to invalid markup somewhere else on that same page.
I need to have datagrid(3 columns) to which the values will be added using 3 textboxes and a button(Add) on the same page. If click on Add button the value should append to datagrid without page refresh/reload?
Please guide me with your approaches to this problem? I ran out of search.
Have you considered using Ajax on the client-side? I presume that clicking the "Add" button is also supposed to update something on the back-end, which means you must do a round-trip of some kind. Either via a postback, but since you don't want this, then the only other option is Ajax whereby you'll make a separate asynchronous post to the back-end that will not cause a page refresh, and on the client script, inject the correct elements to "update" the grid on-screen. You could get that working as a prototype and then use knockout to simplfy the process.
1) I have used iframe in my default aspx page.
2) Created a new aspx page "datagrid.aspx" and had my datagrid as the only control in that page and set the src attribute of iframe to "datagrid.aspx"
3) Datatable to be rendered in datagrid.aspx is stored in the session variable in page load of default.aspx.
4) In the pageload of datagrid.aspx datatable is retrieved and binded to the datagrid.
5) When an item to be added/updated/removed are sent through querystring parameters from default.aspx using onclick event (JS) of a html button by setting the iframe source attribute.
Hope this answer helps.
If its not clear, Please comment.
I have a webpage with a combo box on the page which is loaded with it's data on the Page_Load event of the page.
From that page I have a link which opens another page (within the same IE window) which allows the user to add/remove items that should appear in the combo.
The problem I have is when the user adds a new item to the combo I need this item to appear in the list on the parent page. However when I click the back button on the browser the Page_Load event on the parent page doesn't fire and the new item isn't loaded into the combo.
Want is the best way to handle this?
I'm using ASP.NET 4.0 and IE9.
Thanks in advance.
You could use javascript and call window.parent.location.refresh() on your new window to force a reload.
Best regards.
I have "add new folder" button in my asp.net form and I need to show dialog in order to make the user able to enter the folder name, how can I accomplish that in asp.net?
Add an OnClientClick="ShowPopup();return false;" to the button, and then do:
function ShowPopup() {
var div = document.getElementById("divtoshow");
div.style.display = "block";
}
In the pure form, and then make the div absolute position and reposition the popup to center over the button. Are you using JQuery? You could use JQuery dialog, or use JQuery to position the element, or if you are using AJAX Control toolkit, use the ModalPopupExtender. There are options, but it's hard to tell without knowing what you are using.
HTH.
You have a couple options.
You could include the textbox on the form so that the new folder name is already included.
You could redirect the user to a new form to enter the new folder name.
You could use javascript to include #2 as a thickbox on the current page.
There are other options, it's all in how you want to do it
Update: To accomplish #3, you would have to make another asp.net page, and use a library like Colorbox and load an IFrame inside the thickbox/lightbox
I have a webpage with one iframe and a button.
On Page Load event,
if (!Page.IsPostBack)
{
string sDocUrl = //some doucmen url
Iframe1.Attributes["src"] = sDocUrl;
}
When the page is reloaded (by clicking a button), this iframe is being
reloaded too. This iframe has a static data and doesn't need to be
reloaded everytime when I click a button. Is there a way to prevent
iframe to be reloaded when webform is reloaded?
When a page is reloaded, any iframes contained in it (just as any scrips, images, anything) will always be reloaded. There's no working around that, sorry, simply because the entire page actually reloads.
You could add the iframe dynamically using JavaScript:
if (!Page.IsPostBack)
{
$('#foo').append('<iframe src="' + sDocUrl + '"></iframe>');
}
That uses jQuery to add the iframe to an element with an id of "foo". But it will only add the iframe if the expression in the 'if' statement returns true.