Fair warning: I don't understand half of what I know about this and I don't know that much so please forgive any terms misused or explanations unclear while I'm learning.
I am working on an ecommerce store application. It has an App_Themes with my theme and under that are Scriptlets - header, footer, content, sidebar, etc.
One of those is a Header with the store logo, etc.
Another is the content (of the receipt page in this case).
When a button is clicked on the receipt page I want to set the header scriptlet to go away. I was thinking a CSS display:none but can't figure out how to address that part in another scriptlet. I am not married to that idea either.
I can't directly address controls in a separate scriptlet, apparently.
Some code-ish examples.
Header:
!-- Store Banner-->
<div id="PageBanner">
<div id="PageBannerLogo">
[[ConLib:Custom/StoreLogo]]
</div>
</div>
[[ConLib:Custom/SwitchMobile]]
Content:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ReceiptPageInvoice.ascx.cs" Inherits="ConLib_Custom_ReceiptPage" %>
<%--
<conlib>
<summary>Display page to show details of an order like order items, shipping address, billing address etc.</summary>
<param name="AllowAddNote" default="true">If true, the customer can add notes to the order. If false, the customer can only see notes added by the merchant.</param>
<param name="HandleFailedPayments" default="false">If true, the customer is redirected to an order payment page if the payment fails at checkout.</param>
</conlib>
--%>
<script src="js/showHide.js"></script>
<%--Scrolls address bar out of the way on iphones.
<script type="application/x-javascript">
addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
function hideURLbar(){
window.scrollTo(0,1);
}
</script>--%>
<%# Register Src="~/ConLib/OrderTotalSummary.ascx" TagName="OrderTotalSummary" TagPrefix="uc" %>
<%# Register Src="~/ConLib/BreadCrumbs.ascx" TagName="BreadCrumbs" TagPrefix="uc" %>
<%# Register Src="~/ConLib/Custom/OrderItemDetail.ascx" TagName="OrderItemDetail"
TagPrefix="uc" %>
<%# Register Src="~/ConLib/Utility/PayPalPayNowButton.ascx" TagName="PayPalPayNowButton"
TagPrefix="uc" %>
<%-- this file is identical to ~/ConLib/MyOrderPage.ascx, with the addition of the affiliate tracker tag --%>
<%# Register Src="~/Checkout/AffiliateTracker.ascx" TagName="AffiliateTracker" TagPrefix="uc" %>
<asp:PlaceHolder runat="server" ID="ReceiptPagePh" Visible="True">
<asp:Panel runat="server" ID="InvoicePageTopPnl">
<asp:PlaceHolder ID="BalanceDuePanel" runat="server" Visible="false" EnableViewState="false">
<br/>
<asp:Label ID="BalanceDueMessage" runat="server" Text="** Your order has a balance of {0:lc} due.  <a href='{1}'><u>Pay Now</u></a>"
SkinID="ErrorCondition"></asp:Label>
<br/>
<br/>
</asp:PlaceHolder>
More of the Program....
The button I want to hide the header:
<asp:Button runat="server" ID="ShowTicketButton" OnClick="ShowTicketButton_Click" Text="Show Ticket" />
Skipping from one scriptlet to another is new to me. Within a single conlib is no problems but having a button in one change appearance of another is different. This is a level I've not reached.
Any help is much appreciated.
Jim
Wow, never saw no bites on SO. Probably because I was thinking about it ineffectively. My solution was to simply create a new layout scriptlet that had no header/footer and remove the breadcrumbs conlib from the content scriptlet. Now if we need a header I can just load it into the page and show and hide it at will. Thanks to all who looked at this... I know it's a weird one.
Related
I have an aspx webpage with embedded code block that displays one of the two instances of the same user control. Simplified code:
<form id="form1" runat="server">
<div>
<%if (true)
{ %>
<UC:UserControl runat="server" ID="ucFirst"></UC:UserControl>
<%}
else
{ %>
<UC:UserControl runat="server" ID="ucSecond"></UC:UserControl>
<%} %>
</div>
</form>
Registered user control is cached:
<%# OutputCache Duration="60" VaryByParam="none" %>
However, only ucFirst gets cached, while ucSecond goes through Page_Load and Page_PreRender each time I refresh the page, even though it doesn't appear in rendered HTML code at all. Is it possible to either prevent ucSecond entirely from loading, or load it just once like ucFirst and keep it cached?
I have been trying to get a Modal Popup to work for the last few months. I try and try, and after a while I just give up and find another way to work around it. I am very new to programming and have been doing some helpful things for my department, but in order to make these things viable alternatives I need to get more functionality out of them.
I want to be able to update a row in my SQL server, but the gridview is pulling data from a View, so the built in edit options won't work for me. I was hoping to be able to have a Modal Popup appear on the screen so that I can have the user put the data in and it will build the proper SQL statement to update the row.
I can't even get a Modal Popup with a single line of text to 'popup' though.
At the top of the page I have this:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Then in my main div I have this:
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat=server"></cc1:ToolkitScriptManager>
Then down in the body I have this:
<asp:Button ID="btnTest" runat="server" Text="Test" />
<cc1:ModalPopExtender ID="mp1" runat="server" PopupcontrolID='pnlEdit" TargetControlID=btnTest" OkControlID="btnSubmit" CancelControlID="btnClose" BackroundCssClass="modalBackground" ></cc1:ModalPopupExtender>
<asp:Panel ID="pnlEdit" runat="server" style="display:none">
<div class="modalPopup>
<p>Text goes here.</p>
<asp:Button ID="btnSubmit" runat="sever" Text="Submit" />
<asp:Button ID="btnClose" runat="sever" Text="Close" />
</div>
</asp:Panel>
Code Behind currently has nothing for this. I have tried the same code with the variation of giving the btnTest an OnClick that does mp1.Show();. And also tried adding a "dummy" TargetControlID that is rendered but not shown in order to use the Code Behind to fire.
Every variation produces the same results. The "Test" button is clicked and then nothing happens. It appears that the page is reloaded. What am I missing here?
Please take a look at this Solution
I have created a two usercontrols in asp.net and one webform . Now i want these two usercontrols to show in form in webform but it say that there must be one head with runat="server"
this is webform where i am using UserControl!
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Light.master" CodeBehind="AdministrationPage.aspx.cs" Inherits="DXApplication5.AdministrationPage" %>
<%# Register src="~/AdminPage/AssignmentTab.ascx" tagname="AssignmentUC" tagprefix="uc1" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<table border="0">
<tr>
<td>
<div class="accountHeader">
<uc1:AssignmentUC ID="CalendarUserControl1" runat="server" />
</div>
</td>
</tr>
</table>
</asp:Content>
This is UserControl below:
<%# Control Language="C#" ClassName="AssignmentUC" AutoEventWireup="true" CodeBehind="AssignmentTab.ascx.cs" Inherits="DXApplication5.AdminPage.AssignmentTab" %>
I would add a single form to your masterpage, this may be the cause of your error.
I would also remove all other form server controls from your user controls and pages.
Try these steps:
Go to Light.master master page file and make sure that this is in there somewhere <form id="form1" runat="server"> and a closing tag, the id may be different.
Go to the following files AssignmentTab.ascx and AdministrationPage.aspx and remove any <form id="form1" runat="server"> and closing tags </form>
Check user control code if it contains a head element. Also check all dependencies to see if there are head elements present in them.
I think you have use <form id="formID" runat="server"> in both of your page and user Control .
Just remove runat="server" from your user Control Form tag .
Make sure you have in your user control cs file:
public partial class WebUserControl1 : System.Web.UI.UserControl
In ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebUserControl1" %>
In aspx parent:
<%# Register Src="WebUserControl1.ascx" TagPrefix="uc" TagName="WebUserControl1 " %>
<uc:WebUserControl1 runat="server" ID="mycontrol" />
I have an issue currently that I can't resolve. I have a user control called "Dashboard" which then has the following markup, containing several subcontrols.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.ascx.cs" Inherits="BlueSEQ.Controls.Dashboard.Dashboard" %>
<%# Register src="Administrator.ascx" tagname="Administrator" tagprefix="uc1" %>
<%# Register src="Provider.ascx" tagname="Provider" tagprefix="uc2" %>
<%# Register src="User.ascx" tagname="User" tagprefix="uc3" %>
<% if (isAdministrator)
{ %>
<uc1:Administrator ID="Administrator1" runat="server" />
<% }
else if (isProvider)
{ %>
<uc2:Provider ID="Provider1" runat="server" />
<% }
else
{ %>
<uc3:User ID="User1" runat="server" />
<% } %>
As you can see, I want it to display some controls or other controls depending on some conditions. However, all of these controls' "Load" event get triggered, even if they are not used.
How can I prevent this?
If you can help it, try to avoid having conditional logic in your markup. It could make the views somewhat more difficult to understand for designers (if you're working with designers) and more difficult to find and refactor this code in the future.
You should also take a look at ASP.NET MVC: Avoiding Tag Soup. Although it's ASP.NET MVC, it's still a good example of how adding logic to your views can quickly make them very difficult and unpleasant to maintain (initial example).
You could use the technique described here: How to: Add Controls to an ASP.NET Web Page Programmatically.
Your markup would look something like this.
<asp:PlaceHolder id="MyPlaceholder" />
and your codebehind would have something along the lines of
private void InitSection()
{
Control c;
if( isAdministrator )
c = Page.LoadControl("~\Administrator.ascx")
else if( isProvider )
c = Page.LoadControl("~\Provider.ascx")
else
c = Page.LoadControl("~\User.ascx");
MyPlaceholder.Controlls.Add(c);
}
The ideal way to do this is to set up asp.net role provider and use a LoginView control, something along the lines of the code below. LoginView only loads the appropriate content.
<asp:LoginView runat="server">
<AnonymousTemplate>
<uc1:User ID="User" runat="server" />
</AnonymousTemplate>
<RoleGroups>
<asp:RoleGroup Roles="Administrator">
<ContentTemplate>
<uc1:Administrator ID="Administrator1" runat="server" />
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroup Roles="Provider">
<ContentTemplate>
<uc1:Provider ID="Provider" runat="server" />
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
You have to Load the control on a specific condition instead, so try to set visible/invisible with the usercontrol, that's a much better approach
<% if (isAdministrator)
{ %>
Page.LoadControl(("~\Administrator1.ascx");
<% }
How about using a MultiView control?
MultiView on MSDN
How do you get a server control HTMLAnchor to have href="#". It keeps resolving the "#" to the control path.
<a href="#" runat="server" />
resolves to: <a href="../ControlPath/#">
I can't seem to get a google search to give me the results i want so i figured i'd ask here.
EDIT: Syntax.
Removing the runat server is not an option. It's manipulated in the backend, this was just a simplification.
I had the same problem, here's how I could resolve it:
Original code
User control:
<a id="foo" runat="server">...</a>
Code behind:
foo.Attributes.Add("href", "#");
Output:
<a id="..." href="../Shared/Controls/#">...</a>
Updated code
User control:
<asp:HyperLink id="foo" runat="server">...</asp:HyperLink>
Code behind:
foo.Attributes.Add("href", "#");
Output:
<a id="..." href="#">...</a>
I had a similar issue when rendering the page with PageParser.GetCompiledPageInstance() or when the url was rewritten. For some reason the HtmlAnchor always resolved incorrectly (similar to what you have above).
Ended up just using a HtmlGenericControl, since you are manipulating it server-side anyway this may be a possibility for you.
HtmlGenericControl anchor = new HtmlGenericControl("a");
anchor.Attributes.Add("href", "#");
Brendan Kowitz solution will work, however i was not able to implement it due to the way this control is to operate. I ended up having to hack it as per the following code in the code behind:
lnk.Attributes.Add("href",Page.Request.Url.ToString() + "#");
Where lnk is an HtmlAnchor.
The reason for this issue in the first place is the control is not in the same directory as the page, and .Net goes about "intelligently" fixing your problem for you. The above will work, though if anyone has a better solution i'm all ears.
Originally I had this as a comment but by request I'm adding it as an answer since nobody else has explained why the original behavior is occurring or how to directly prevent it.
The URL rewriting is caused by the method ResolveURL on the Control class. I looked at it in Reflector and found that it will attempt to rewrite anything that it thinks is a relative URL if AppRelativeTemplateSourceDirectory is non-empty.
The simple workaround is to set this variable on the Page object to an empty string at some global level (or at least before Render), although this could be an issue if some other bit of your control structure requires it to be empty.
I suppose a true fix would be to get Microsoft to make UrlPath.IsRelativeUrl() smarter.
I ran into the same thing. If you set this on page load, it will work:
AppRelativeTemplateSourceDirectory = "";
Try removing the "runat" attribute and wrapping what you want to link;
<a href="#" >Your Link Text/Image Here</a>
This should work.
text
This should work.
text
Mine too works fine...I have a user control AnchorTag.ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AnchorTag.ascx.cs" Inherits="JavascriptScroll.AnchorTag" %>
<a id="A1" href="#" runat="server" >Anchor Tag</a>
And I included it as :
<%# Register src="AnchorTag.ascx" tagname="AnchorTag" tagprefix="uc1" %>
.
.
.
<uc1:AnchorTag ID="AnchorTag1" runat="server" />
.
.
And it renders as expected:
Anchor Tag
Please correct me if I'm doing something which is not expected...
EDIT: Includes nested paths
My test project renders the correct link for me:
http://localhost:2279/WebSite1/Default.aspx#
ASPX:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register src="control/WebUserControl2.ascx" tagname="WebUserControl2" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:WebUserControl2 ID="WebUserControl21" runat="server" />
</form>
</body>
</html>
Control:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl2.ascx.cs" Inherits="WebUserControl2" %>
<a id="A1" href="<%# URLHelper("~/#") %>" runat="server" >here</a>
Control Code-Behind:
protected string URLHelper(string s)
{
return Control.ResolveUrl(s);
}
What about this?
HtmlAnchor errorLink = new HtmlAnchor();
errorLink.InnerText = this.Message;
errorLink.HRef = errorLink.ResolveClientUrl("#" + this.FormControlId);
errorLink.Attributes["rel"] = "form_help";
Works for me but I'm using a Server Control in a Class Library as opposed to a User Control. I think it should work for a User Control as well.