I am trying to create a website that will allow sharing photos (as a basic project),
and i encountered a problem.
On my masterPage there are links with category names and I need that when i click on one of them I would get a Value into a variable in a child page (in the css code page).
I am pretty new to masterpages and have no idea how to do so, i tried in some ways but just couldn't.
As an example:
A string variable in the css section of the child page "Gallery.aspx" that would get the value of the category name when it's clicked in the masterpage.
Hyperlink hh=(Hyperlink)Master.FindControl("control_name");
reference
Related
I'm trying to achieve overriding of existing 'Theme' pages, located in 'Pages/Theme', by placing another page with the same name in the 'Pages/Overrides' folder.
I have done so by creating a PageRouteModelConvention named ThemeTemplatePageRouteModelConvention. Any pages in the 'Pages/Overrides' folder will be reachable without the '/Overrides/' route prefix and have priority over the similarly named view in the 'Pages/Theme' folder.
See my example repository here: https://github.com/bryandh/razor-page-override
In the current setup, we have three pages in Pages/Theme:
Index
About
Contact
And two pages in Pages/Overrides:
Index
About
The behaviour that I would like to have with these pages:
Index page with / route used from Pages/Overrides
About page with /about route used from Pages/Overrides
Contact page with /contact route used from Pages/Theme
This works as I want it to work.
However, the anchor tags created in the Pages/Theme/Components/_Header partial to a non-overriden page in Pages/Theme using the anchor tag helper does not create the correct route.
See the root/index page where the _Header component is included. The About page link is generated correctly as the About page is also in the same folder. However, the Contact page link does not seem to be generated properly. This link to the Contact page only works when you're on the Contact page itself, as that is situated in Pages/Theme.
Generation of the anchor tag doesn't seem to take the locations views can be situatied in into account.
Because the link is in a component that I do not want to override, I can't modify the asp-page attribute to fix the problem.
How can I let the Header component generate a link to the Contact Theme page from the overriding Index page?
[UPDATE]
To clarify further, see the page override structure below.
The asp-page tag helper can't find the Contact page to create a route for.
Note: the Contact page is reachable by manually navigating to /contact.
I have a user control, say control 1, that looks for control2, which is placed on the root master page : Site.Master
And this is how I am getting Control2 from Control 1 now,
MasterPage showMaster = this.Page.Master.Master;
MasterPage siteMaster = showMaster.Master;
Control2= siteMaster.FindControl("Control2");
The above code works fine. But because our application uses nested master pages, I am running into a bit of situation here.
How do I find control 2 dynamically regardless of where I put Control1 in which template? Becasue right now, depends on where I put Control1, and how nested is that template in relation to the Site.Master, I have to change how far up in the chain I get Site.Master in the Control 1 code.
Any good ideas on how I can avoid doing that?
Please advise.
i found a work around with recursively loading the control
I want to open a regular .aspx page in a rad window.But the regular page consists of Site Map.I don't want that sitemap to be displayed when it is opened in rad window.
Please suggest me some solution.
I already tried this:
this.MasterpageFile="..//test.Master";
But in my page it does not work
So you will have ContentPlaceHolders which will automatically inherit from the master page. If you go to the regular .aspx page and head into Design view you will see sections with all the content from the Master Page.
If you click the little right arrow to the right of the area that looks like a Div, you should be able to change the content back to what you have in your regular aspx page.
Make a public property on MasterPage to show hide your site map , on your rad window page access that Property and make it hide.
public bool MyProperty()
{
// get and set your controls visibility
}
Access your property like this.Master.MyProperty = false
I want to make a label invisible in child page which is defined in master page.
Is there a way to do that?
((Label)Master.FindControl("mylbl")).Visible = false;
put this in page load of the child page , mylbl refers to the ID of the label
it might be Master.Page.FindControl .... now that I think of it, it's been a while , but that's how you do it
You should use javascript. Normally in this situation, you would reference your label using
(assuming your label's ID is my_label_id)
document.GetElementById('<%= my_label_id.ClientId %>')
. . . or if you are using jquery . . .
$('#<%= my_label_id.ClientId %>')
However, AFAIK you cannot use clientid to reference a server-side control located on the master page from a content page. So I would either give the control a unique class name using the asp.net label attribute CssClass="myLabelClass" or retrieve the client Id by building the page, viewing the source, and finding the client ID. Steps for this can be found here:
How to use javascript in content page, asp.net
Once you correctly reference the item, simply change the "display" style attribute to "none" as seen below.
Using jQuery and assuming your CssClass name is myLabelClass:
$('.myLabelClass').css('display','none');
If you wanted this to occur on page load you could do the following:
$(function(){
$('.myLabelClass').css('display','none');
});
I need to have a button on the master page.
Once that button is clicked I generate a string that represents URL.
test.apx is a content page I use and the string will look like something like this:
Example:
www.blah.com/test.aspx?user=blax&develop=extreme_all
Now all I need is to reload the page while content is redirected to the URL I generated.
I hope this makes more sense.
Thanks guys I am new to asp.net and really appreciate any help
Why dont you use Update Panel?
Have the page postback with the updated query string to change what is in your content area
Assuming your masterpage is set up correctly
within the <asp:content> tag of your aspx page that is using the masterpage you created add code to get the query string
Request.QueryString["key"]
example url: http://www.whatever.com?foo=bar&bar=foo
string tmp = Request.QueryString["foo"]
tmp will become "bar"
Now just check the "postback" option of the asp:control you're using to reload the content page or do whatever you to make the page refresh.
If I understand your question correctly, you want to reuse the same code to parse out your user and develop variables from different content pages that use the same master page.
It sounds like you need a strongly typed master page.
First, put your shared code in your master page. Then, expose the parsed data as properties of the master page. Next, simply add the following directive in your content pages:
<%# MasterType VirtualPath="~/mymasterpage.master" %>
Finally, in your content pages, you can reference your properties as such (assuming you created a property called MyUser):
string user = this.Master.MyUser;
You can also use inheritance if you want a different approach. Simply create class that inherits from Page. Then put your shared code in that class. Finally, make your content pages inherit from your new class, instead of Page.