When I use a ASP:Calendar control, and give it an ID:
<asp:Calendar runat="server" ID="MyCal" />
It looks like this in the rendered html:
<table id="NameMangled_MyCal"... />
And I can access the element by ID in javascript like this:
var cal= document.getElementById("<%= MyCal.ClientID%>")
However, When I make a custom user control that has-a calendar:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div>
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
And then give it an ID when I add it to my page...
<mvs:WeeklyEventsCalendar ID="WeeklyCal" runat="server" />
That ID doesn't show up anywhere in the rendered HTML. all I get is
<div> stuff </div>
When I want
<div id="NameMangled_WeeklyCal"> stuff <div>
What am I doing wrong?
UserControls only render their contents, nothing else. What you could do is
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div id="<%= this.ControlID %>">
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
Related
I have created .Master, .aspx and .ascx pages. I want to call .ascx page upon click on button in .master page. If the button is not clicked then .ascx should not show up.
Currently, Onload of page, .ascx page is calling because i have used <uc1:Account runat="server" ID="Account" />. But i want after click of button not on page load.
Any help is highly appreciated. Thank you in advance.
My master page looks like this:
<%# Master Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Staff.master.cs" Inherits="Admin_Staff" %>
<%# Register Src="~/Controls/Account.ascx" TagPrefix="uc1" TagName="Account" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h4>Account</h4>
<span class="input-group-btn">
<input type="text" class=" search-query form-control" placeholder="Search" />
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
<div class="col-lg-9">
<uc1:Account runat="server" ID="Account" />
</div>
</asp:Content>
My User Control looks like this:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="Acc.ascx.cs" Inherits="Admin_Controls_Account" %>
<asp:panel id="pnlAcc" runat="server">
<section id="AccForm">
<asp:PlaceHolder runat="server" ID="PlaceHolder1" Visible="false">
</asp:PlaceHolder>
<div class="form-group">
<asp:Label runat="server" CssClass="col-md-2 control-label">Country: </asp:Label>
<div class="col-md-10">
<asp:Label runat="server" CssClass="col-md control-label" >New Zealand</asp:Label>
</div>
</div>
</section>
</asp:panel>
My .aspx page
<%# Page Title="" Language="C#" MasterPageFile="~/Admin/Staff.master" AutoEventWireup="true" CodeFile="Staff.aspx.cs" Inherits="Admin_Staff" %>
<asp:Content ID="Content1" ContentPlaceHolderID="StaffContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" Runat="Server">
</asp:Content>
You can set the Visibility of the Control to false and change it on Button Click
<uc1:Account runat="server" ID="Account" Visible="false" />
And then on button click
protected void Button1_Click(object sender, EventArgs e)
{
Account.Visible = true;
}
Or you can add the Controls dynamically
protected void Button1_Click(object sender, EventArgs e)
{
Admin_Controls_Account account = (Admin_Controls_Account)LoadControl("~/Controls/Account.ascx");
PlaceHolder1.Controls.Add(account);
}
Note that for the last option you will have to reload the control each time there is a PostBack so you will have to store the Visibility yourself and recreate the control each time the page is loaded.
Simple way is to make the control invisible on the master page.
<uc1:Account runat="server" ID="Account" Visible="False" />
Make it visible on button click.
I have a masterpage like this
<%# Master Language="C#" MasterPageFile="~/masterpages/XmasShop.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="cphContents" runat="server">
<asp:LoginView runat="server" ID="lview1">
<LoggedInTemplate>
<div class="confirmation-cantainer">
<div class="confirm-01">
<form runat="server">
<umbraco:Macro Alias="[Xmas]ShopConfirm" runat="server"></umbraco:Macro>
</form>
</div>
</div>
</LoggedInTemplate>
</asp:LoginView>
</asp:Content>
<asp:Content ContentPlaceHolderID="cphAuthenticationPane" runat="server">
<asp:LoginView runat="server" ID="lview12">
<LoggedInTemplate>
<form runat="server">
<asp:LoginStatus ID="lslougout" runat="server" Style="float: right; color: #003263; text-decoration: none;" text="Logout"></asp:LoginStatus>
</form>
</LoggedInTemplate>
</asp:LoginView>
</asp:Content>
And you can see I have two form tags in it,but both are seperate not nested.Still I am getting an error
A page can have only one server-side Form tag.
Can any one suggest me a solution.When I tried to remove one of the forms its throwing an error elements must be inside a form tag and when I add form above error.
Use the following tutorial to set up two form tags and be able to toggle them on and off, as required:
http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html
One solution is to have the login information on a separate page. You could also look into using an iframe.
This error occurred due to use of more than one
<form runnat="server">
tag.
Remove one of the form tag.
This would be more clear by visiting this link
So I'm the new guy on the dev team, trying to update a "Dashboard" type page, which is the default landing page for our users. The default.aspx page consists of 16 Web User Controls (.ascx). I've been asked to add stock "widget" on the dashboard, so users can monitor our company's stock symbol. To allow for different timeframes (1 day, 5 day, 3 month, etc) I was planning on using a Menu (tabs) within a new .ascx. When I try to use a menu, I get the error "Control 'StockDisplay_StockMenu' of type 'Menu' must be placed inside a form tag with runat=server". If I wrap the menu in form tags, I get the "A page can have only one server-side Form tag" error.
Most search results suggest looking at the Master Page, but we're not using one here. I checked The default.aspx page, and it does not have any form tags. Other searches suggested removing < head> and < body> tags in the .ascx, which I've done, but still I have the issue.
Here's my stripped down code, which still produces the error:
<%# Control Language="VB" AutoEventWireup="false" CodeFile="UC_StockDisplay.ascx.vb" Inherits="UC_StockDisplay" %>
<%# Import Namespace="System.Data" %>
<form id="Form1" runat="server">
<asp:Menu ID="StockMenu" runat="server">
<Items>
<asp:MenuItem Text="One Day" />
<asp:MenuItem Text="Five Days" />
<asp:MenuItem Text="Three Months" />
<asp:MenuItem Text="Six Months" />
<asp:MenuItem Text="One Year" />
</Items>
</asp:Menu>
</form>
Here's the default.aspx:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%# Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%# Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%# Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%# Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%# Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%# Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%# Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%# Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%# Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%# Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%# Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%# Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%# Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%# Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%# Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%# Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>
<!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>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">
<center>
<img src="images\banner2.gif" border=0><br>
<font face="Courier New Bold" size=5 color=white>Helpdesk 3.5</font><br>
<table width=100% cellspacing=10>
<tr>
<td width="33%" valign=top>
<uc1:HelpUs ID="HelpUs" runat="server" />
<br>
<uc3:ImportantLinks ID="ImportantLinks" runat="server" />
<br>
<uc10:Directory ID="Directory" runat="server" />
<br>
<uc6:UCRequestForms ID="UCRequestForms" runat="server"/>
<br>
<uc7:MiscLinks ID="MiscLinks" runat="server" />
</td>
<td width="33%" valign=top align=center>
<uc5:WorkOrder ID="WorkOrder" runat="server" />
<br>
<uc8:Emergency ID="Emergency" runat="server" />
<br>
<uc2:ImportantNumbers ID="ImportantNumbers" runat="server" />
<br>
<uc11:Weather ID="Weather" runat="server" />
<td width="33%" valign=top>
<uc17:StockDisplay ID="StockDisplay" runat="server" />
<br />
<uc9:Floorplan ID="Floorplan" runat="server" />
<br>
<uc4:Printers ID="Printers" runat="server" />
<br>
<uc15:MyInfo ID="MyInfo" runat="server" />
<br>
<uc14:CoreValues ID="CoreValues" runat="server" />
<br>
<uc12:Holiday ID="Holiday" runat="server" />
<br />
<uc16:Travel ID="Travel" runat="server"></uc16:Travel>
</td>
</tr>
</table>
</center>
</body>
</html>
After adding one control you have a form with runat="server" tag:
<form id="Form1" runat="server">
<asp:Menu ID="StockMenu" runat="server">
You already mentioned you have 16 usercontrol in one page. So you have 16 forms with runat="server" tag. Which is not allowed.
Solution: As Chris Lively suggested, strip out the the form tag from your wsercontrols. Add just one form tag in the page. You should be ok.
Here's how should all your controls should look like:
<asp:Menu ID="Menu1" runat="server">
<Items>
<asp:MenuItem Text="One Day" />
<asp:MenuItem Text="Five Days" />
<asp:MenuItem Text="Three Months" />
<asp:MenuItem Text="Six Months" />
<asp:MenuItem Text="One Year" />
</Items>
</asp:Menu>
And your page should look like:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%# Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%# Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%# Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%# Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%# Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%# Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%# Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%# Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%# Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%# Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%# Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%# Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%# Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%# Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%# Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%# Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>
<!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 id="Head1" runat="server">
<title>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">
<form id="form1" runat="server">
<%-- your usercontrols and other tags --%>
</form>
EDIT: As you mentioned other usercontrols don't have forms, just adding form tag in the main page and remove that tag from usercontrol should solve your problem.
I am trying to execute the following code in a .aspx page:
<asp:Repeater ID="rptComentarios" runat="server">
<ItemTemplate>
<% if (Convert.ToInt32(Eval("int_tipo")) == 1)
{ %>
<div class="resp">
<div class="top">
</div>
<div class="cont-resp">
<h3>
<%# Eval("txt_nome") %></h3>
<p>
<%# Eval("txt_comentario") %></p>
</div>
</div>
<% }
else
{%>
<div class="usuario">
<div class="top">
</div>
<div class="cont-usuario">
<h3>
<%# Eval("txt_nome") %></h3>
<p>
<%# Eval("txt_comentario") %></p>
</div>
</div>
<% } %>
</ItemTemplate>
</asp:Repeater>
It throws a runtime exception in the first line:
<% if (Convert.ToInt32(Eval("int_tipo")) == 1)
System.InvalidOperationException: Databinding methods such as Eval(), XPath() and Bind() can only be used in the context of a databound control.
What's wrong? Any ideas?
I had a similar problem and the following code worked for me:
<asp:Repeater ID="rptComentarios" runat="server">
<ItemTemplate>
<asp:PlaceHolder ID="placeholderBlaBlaBla" runat="server" Visible='<%# Convert.ToInt32(Eval("int_tipo")) == 1 %>'>
Your optional HTML
</asp:placeholder>
Other HTML
</ItemTemplate>
</asp:Repeater>
Some more comments:
Please note that single quotes are used to define the value Visible attribute of asp:placeholder. I tried double quotes too and they didn't work.
Anytime you want to get some optionally displayed HTML you should use a control to show/hide it. asp:placeholder works fine for that purpose. Don't ever do <% if(..) { %> - this is evil.
<%# ... %> is used to calculate or display expressions inside a repeater. These expressions can be displayed as HTML or passed as attributes of server side controls. You can't use if inside it.
I think there needs to be a # sign for the enclosure <%# ..Eval...%>
Or try the full Eval version
<%# if (Convert.ToInt32(DataBinder.Eval(Container.DataItem, "int_tipo"))
== 1) { %>
My tab control items contain three different pages.Clicking on tabitem ,they are visible,but when want to perform javascript event on page item then problem arise.javascript well works for only first tab control item,rest of them are not work.Show me the bellow error.
Microsoft JScript runtime error: 'this.GetStateInput().value' is null or not an objec
tabcontrol
**tab item1 contain page1
tab item2 contain page2
tab item3 contain page3**
i write javascript on page1 control,it's work well but rest of pages javascript show the above error message. i work on devexpress control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="UCCharge.ascx.cs" Inherits="WebCore.UserControls.ChargeSettings.UCCharge" %>
<%# Register assembly="DevExpress.Web.v9.1, Version=9.1.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxTabControl" tagprefix="dxtc" %>
<%# Register assembly="DevExpress.Web.v9.1, Version=9.1.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxClasses" tagprefix="dxw" %>
<%# Register src="UCConfig_Charge_Company_Wise.ascx" tagname="UCConfig_Charge_Company_Wise" tagprefix="uc1" %>
<%# Register src="UCConfig_Charge_Depository_Company_Wise.ascx" tagname="UCConfig_Charge_Depository_Company_Wise" tagprefix="uc2" %>
<%# Register src="UCconfig_charge_operation_mode.ascx" tagname="UCconfig_charge_operation_mode" tagprefix="uc3" %>
<%# Register src="../InvestorAccount/UCconfig_Investor_Account_Wise_Charge.ascx" tagname="UCConfig_Investor_Account_Wise_Charge" tagprefix="uc4" %>
<table>
<tr>
<td>
<dxtc:ASPxPageControl Width="500px" ID="ASPxPageControl1" runat="server" ActiveTabIndex="0"
EnableCallbackCompression="True" EnableHierarchyRecreation="True"
AutoPostBack="True">
<TabPages>
<dxtc:TabPage Text="Charge Company">
<ContentCollection>
<dxw:ContentControl ID="ContentControl1" runat="server">
<uc1:UCConfig_Charge_Company_Wise ID="UCConfig_Charge_Company_Wise" runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Charge Depository Company">
<ContentCollection>
<dxw:ContentControl ID="ContentControl3" runat="server">
<uc2:UCConfig_Charge_Depository_Company_Wise ID="UCConfig_Charge_Depository_Company_Wise"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Investor Charge ">
<ContentCollection>
<dxw:ContentControl ID="ContentControl5" runat="server">
<uc4:UCConfig_Investor_Account_Wise_Charge ID="UCConfig_Investor_Account_Wise_Charge"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Charge Operation Mode ">
<ContentCollection>
<dxw:ContentControl ID="ContentControl4" runat="server">
<uc3:UCconfig_charge_operation_mode ID="UCconfig_charge_operation_mode"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
</TabPages>
</dxtc:ASPxPageControl>
</td>
</tr>
</table>
I read on a Support issue of a user getting this error, in his case it was because he was using value (myTextBox.value) when getting the value of a DX Control instead of the GetValue() (myTextBox.GetValue()) client method DX provides. Could this be the same thing happening in your code as well?