Got a very frustrating problem that I'm trying to solve regarding C#.NET's way of handling dynamically added usercontrols.
The basic rundown of my page setup is that I have an ASPX page which has a Master Page. The Master Page has some content placeholders. On the codebehind in the ASPX page, I call the Master.FindControl method to find the content placeholders, and then use the LoadControl method to load a UserControl into the placeholder.
On the UserControl, I have a series of textboxes, and a submit button. In this implementation, when I click on the submit button, and put a breakpoint into the OnClick event, I find that the OnClick event is never called.
However, if, instead of using this approach, I remove the Master Page, and add the content placeholders directly on the ASPX page, then use Placeholder.Controls.Add to add the UserControl instead of Master.FindControl, the button works perfectly.
Does anyone have any suggestions as to how I can resolve this without removing the Master Page?
Related
I'm making an ASP.NET application that performs some globalization in the Render event of the Master Page. Basically my code uses regular expressions to look for placeholders (text patterns, not actual PlaceHolder controls) in the markup and replaces them with the corresponding translations found in an XML file.
This works as intended when the page is loaded normally, but on a partial postback the Render event does not seem to trigger at all for the Master Page, leaving the rendered page full of placeholders. The event does trigger for the current Page however, but I don't want to alter the output HTML separately in every single page's Render event.
The ContentPlaceHolder (containing the current Page) of the Master Page is located inside an UpdatePanel, and I assume this has something to do with what is happening. I still don't understand why the event is not triggered, however.
Is there a way to force the Master Page Render event to trigger on partial postback, or should I consider a different solution?
I wanted to load a .aspx page into contentplaceholder without making a postback. What I have is a master page with 3 contentplaceholders
1.headerContent
2.leftContent
3.mainContent
I have 3 links in the headercontent and according to the selection of those 3 links, i'm showing few menu's on the leftcontent. On selecting any of the loaded menu on the left content i wanted to show/load a .aspx page inside the "maincontent" through the codebehind(C#), without making a refresh or postback. The .aspx pages which i wanted to load aren't inheriting the masterpage.
Other than using Iframes, is there any way to accomplish this??
What I can suggest is to use user controls (.ascx) instead of pages. Have one page that loads all the controls from the start, this page will use the master page and will have its content place holder as the mainContent.
You can have each control inside a div on the page, and set the display of the div to none. Then you can use java script to display just the relevant user control.
In ASP.NET, I have a master page, and five other pages which are under master page.
In all five pages, I need to implement a button, after clicking it, will generate different download results.
My original implementation is, in all five page, will all have a "Button", so in code behind will have corresponding event method to generate the download.
But my approach, will have duplicated html compoents.
Is there a way I can define the download button in my master page, when clicking button in different page, event method from different page will be invoked?
Yes you can, on master page you can have a Download Button and on it click check the URL, which will help you to identify the request has come from which page. Then you can write code on the basis of current page being displayed.
You can use the SHTML instead of HTML and include it every where that you need it.
I don't know what exactly You want to achieve, but maybe it would be better to have one aspx with the button and load the correct ascx file to this page according to some criteria? Each ascx can derive from some interface with some method, f.e. Click(), and each time the button on aspx is clicked, the Click() method from currently loaded ascx can be called.
How can I access a control on page a.aspx from a webusercontrol.ascx
I do not know the technical term used to describe this, if any,
the webusercontrol.ascx page contains a button.
onclick of the button, placeholder on main page must display the "required content".
if this were on the same page no problem.
but how to access across pages?
Expose an event on your ASCX control, subscribe an event handler method on the ASPX page to the event on that page's instance of that control, implement the method to make the required changes to the parent page.
From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".
Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say
Response.Redirect("PageB.aspx");
But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.
In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.
Is this possible, if so how?
I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.
ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.
Using user controls (.ascx):
Create a page that uses the MasterPage and use something like this in the content
<ajax:UpdatePanel ...>
<ContentTemplate>
<asp:PlaceHolder ...>
</ContentTemplate>
</ajax:UpdatePanel>
Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.
No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.
More Info:
You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.
There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.