MasterPage:
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
ASPX page:
<%# Page Title="" Language="C#" MasterPageFile="~/NewFMaster.master" AutoEventWireup="true" CodeFile="Home17.aspx.cs" Inherits="Home17" %>
....
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
....
<form id="form1" runat="server">
<div class="form-group">
<div class="col-sm-6">
<asp:TextBox ID="txtFullName" runat="server" CssClass="name" placeholder="Full Name"></asp:TextBox>
</div>
<div class="col-sm-6">
<asp:TextBox ID="txtContact" runat="server" MaxLength="12" CssClass="name" placeholder="Contact Number" />
</div>
</div>
<asp:Button ID="submitButton" runat="server" CssClass="submit-btn" style="width:150px" Text="Submit" OnClick="submitButton_Click"/>
</form>
....
</asp:Content>
CodeBehind:
public partial class Home17 : System.Web.UI.MasterPage
{
....
protected void submitButton_Click(object sender, EventArgs e)
{
Response.Redirect("Home16.aspx");
}
If I remove OnClick="submitButton_Click" from asp:Button line, then the page atleast displays, otherwise I get "Internal Server error"
Web.Config: CustomerErrors are off & have tried with both true/false for debug
UPDATE 24 Apr 2018:
Now Internal Server Error is shown on all pages. Entire site has gone done.
In the error Log last error is:
(I have added the new keys)
<Error>
<Message>Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster,
ensure that <machineKey> configuration specifies the same validationKey and validation algorithm.
AutoGenerate cannot be used in a cluster.
http://go.microsoft.com/fwlink/?LinkID=314055</Message>
<PageName>http://www.***.*******.com/Product.aspx?productID=69584&productID=69584</PageName>
<Date>4/23/2018 8:58:44 PM</Date>
<UTC>4/24/2018 3:58:44 AM</UTC>
</Error>
Note: The hosting provider is BigRock. (have asked them for help but they simply said I'll have to resolve it, its not their issue)
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 program that reads book info from a database and creates a shopping cart program. It runs fine locally but whenever I test it on my site, I get an Error 500 - Internal Server Error. I've found out that if I comment out the asp:button in the code below, the program works but the button is necessary. The Button3_Click function exists in the code behind. Any ideas?
<div id="book3" class="books" style="width: 170px; height: 351px; float:left;">
<asp:Image ID="Image3" runat="server" Height="196px" Width="169px" ImageUrl="url/ofMiceandMen.jpg" />
<br />
<div style="height: 135px">
<asp:Label ID="title" runat="server" Text="Of Mice and Men"></asp:Label>
<asp:Label ID="author" runat="server" Text="John Steinbeck"></asp:Label>
<asp:Label ID="review" runat="server" Text="4.5/5 Stars"></asp:Label>
<asp:Label ID="price" runat="server" Text="$7.00"></asp:Label>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="View Book" />
//This Button
</div>
</div>
This is what the server tells me when I specify for detailed debug info.
Detailed Error Information:
Module: ManagedPipelineHandler
Notification: MapRequestHandler
Handler: PageHandlerFactory-Integrated-4.0
Error Code 0x00000000
I encountered the same error and I researched but found a lot of answers that did not fix it. Here are my solution steps
If the page is a html page, add a form tag with an id and runat inside the <body> tags
<form id="form1" runat="server">
<div>
<!--Add your button -->
</div>
</form>
and possibly add a <div></div> inside the <form> tags
This question already has answers here:
find a control in current page
(3 answers)
Closed 7 years ago.
I want to find the control ddlMaster.
Here is the excerpt aspx rah_sync_output.aspx in question:
<%# Page Language="vb" MasterPageFile="~/admin/Admin.master" AutoEventWireup="false" CodeBehind="rah_sync_output.aspx.vb" Inherits="TCDS.Web.admin.RahSyncOutput" EnableEventValidation="false" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Button ID="btnExport" runat="server" Text="Export To Excel" OnClick = "ExportToExcel" /><br />
Locations
<asp:DropDownList ID="ddlMaster" runat="server" OnSelectedIndexChanged = "FilterChanged" AutoPostBack = "true" AppendDataBoundItems = "true">
</asp:DropDownList>
</asp:Content>
Here is the masterfile /admin/Admin.master excerpt:
<%# Master Language="VB" Inherits="XXX.Web.admin.AdminAdmin" Codebehind="Admin.master.vb" MasterPageFile="~/fullPage.master" %>
<asp:Content ID="headerContent" ContentPlaceHolderID="headContent" runat="server">
<asp:contentplaceholder id="head" runat="server">
</asp:contentplaceholder>
</asp:Content>
<asp:Content ID="menuContent" ContentPlaceHolderID="tcdsMenu" runat="server">
<ul class="ulMenu" style="">
<asp:Literal ID="ltrMenu" Text='' runat="server" />
</ul>
</asp:Content>
<asp:Content ID="tcdsContent" ContentPlaceHolderID="tcdsContent" runat="server">
<div id="content">
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</asp:Content>
Here is the masterfile's masterfile fullPage.master excerpt:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="box">
<div id="divHeader" runat="server">
<asp:Literal ID="ltrAgencyLogo" runat="server" />
<asp:Literal ID="ltrAgencyName" runat="server" />
<a id="xxxicon" class="icnMCLLC" href="http://www.hidden.com" target="mcllc" runat="server">
<img src="/tcds/images/xxx.gif" border="0" alt="Click for technical assistance" width="110" height="36" />
</a>
<div class="bannerIcon"><img src="/tcds/images/icnHelp.gif" border="0" alt="TCDS Help" style='width: 24px;height: 24px;' /></div>
<span class="header"><asp:Literal ID="ltrHeader" runat="server" /></span>
<asp:contentplaceholder id="tcdsMenu" runat="server">
</asp:contentplaceholder>
</div>
<div id="content">
<asp:contentplaceholder id="tcdsContent" runat="server">
</asp:contentplaceholder>
</div>
</div>
</form>
My attempt in rah_sync_output.aspx.vb:
Dim ddl = DirectCast(Master.FindControl("tcdsContent").FindControl("ContentPlaceHolder1").FindControl("ddl" + columnName), DropDownList)
where columnName is "Master" at runtime.
Result is null. I either misunderstand that Master refers to the current master or the master's master. All I want to do is reference controls inside ContentPlaceHolderID="ContentPlaceHolder1"
Master.FindControl("tcdsContent").FindControl("ContentPlaceHolder1").FindControl("ddl" + columnName)
That's one way to do it, but you're probably missing a naming container somewhere in the control hierarchy. It would be easier to find the control recursively.
/// <summary>
/// recursively finds a child control of the specified parent.
/// </summary>
/// <param name="control"></param>
/// <param name="id"></param>
/// <returns></returns>
public static Control FindControlRecursive(this Control control, string id)
{
if (control == null) return null;
//try to find the control at the current level
Control ctrl = control.FindControl(id);
if (ctrl == null)
{
//search the children
foreach (Control child in control.Controls)
{
ctrl = FindControlRecursive(child, id);
if (ctrl != null) break;
}
}
return ctrl;
}
i wrote below code . but i do not know why i get error. but every thing seems ok.
it says there are not my text boxes in context. but there are .
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<form id="form1" runat="server">
<asp:TextBox ID="address" runat="server"/>
<div class="form1">
<label for="fname">
<span>name:</span>
<asp:TextBox ID="fname" runat="server"/>
</label>
<label for="lname">
<span>lname: </span>
<asp:TextBox ID="lname" name="lname" runat="server" />
</label>
.
.
.
</div>
protected void send2_Click(object sender, EventArgs e)
{
tbl_register tbl = new tbl_register();
tbl.firstname = fname.Text; // The name 'fname' does not exist in the current context
tbl.lastname = lname.Text; // The name 'lname'does not exist in the current context
tbl.address = address1.Text; //..
tbl.phone = phone.Text; //..
tbl.email = email3.Text; //..
db.tbl_registers.InsertOnSubmit(tbl);
db.SubmitChanges();
}
The textboxes as coded are children of the label. I do not code my lables in that way. In order to use controls that are child controls you must use Control.FindControl, in this case fname.FindControl("fname"). I would not name controls the same as other controls. You can also close the label tag such that it does not enclose those controls, and then the control can be referenced via the name.
the line
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
suggests that this is a webform that uses a MasterPage.
inside the content place holder you have a form declaration that runs at server:
<form id="form1" runat="server">
however, on your MasterPage.master you already have a form that runs at server that wraps the content placeholder.
asp.net does not allow 2 nested forms to both run at server.
I am reposting the question, since it has changed a lot since I had problems with it initially, I know where the problem is but i do not know how to fix it, or the cause of it at all.
So i have 2 master files, one is for a login page and another one for the inside content. I also have a default.aspx file and a logout.aspx file. They both use the MasterPage.master which is the initial page. What i found out is, when I exclude the Logout.aspx from the project and run it, the website initial page uses the .css file. When I include the logout.aspx debug the program, the initial screen uses the .css at first then when i log in and log out, it shows the default.aspx without the .css. If I try to debug the page again, then the initial screen no longer uses the .css.
My master class has this:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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>
<link href="~/StyleSheet.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<div class="login">
<div class="container">
<div class="header">
<h1 id="site-name">
<font color="black" size="5">SES Users Admin</font>
</h1>
</div>
<!--Hello Content -->
<div class="content">
<asp:Label ID="lblUsername" runat="server" Text="Username"></asp:Label>
<asp:TextBox ID="txtUsername" runat="server" Height="21px"
style="margin-left: 2px" Width="133px"></asp:TextBox>
<br /><br />
<asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Height="20px"
style="margin-left: 4px" Width="133px"></asp:TextBox>
<br /><br />
<div class="button">
<asp:label id="lblResult" runat="server" Width="100%"></asp:label>
<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnlogin_Click"
Width="57px" Height="21px"/>
</div>
</div>
</div>
</div>
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</form>
</body>
</html>
Default aspx and default.cs are both empty like so:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="head">
</asp:Content>
<asp:Content ID="MainerContent" runat="server" ContentPlaceHolderID="MainContent">
</asp:Content>
As well as logout except for the logout.aspx.cs which contains the logout function:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Logout.aspx.cs" Inherits="Logout" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="head">
</asp:Content>
<asp:Content ID="MainerContent" runat="server" ContentPlaceHolderID="MainContent">
</asp:Content>
CS
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HelloApp;
public partial class Logout : Page
{
protected void Page_Load(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("default.aspx");
}
}
Take a look at browser requests in firebug / fiddler / charles to see what's happening to the request for the CSS file.
Try viewing the source of a page on the site and look for the <link ...> tag. What css file does it point to?
I suspect that your Site.css is not in the same folder as your MasterPage/ContentPage.
If your link to the stylesheet is simply Site.css then what ever the folder your MasterPage/ContentPage or just the ContentPage is in will be looking for the stylesheet in that folder.
e.g. if using <link rel="Stylesheet" type="text/css" href="Site.css" />
/Folder1/ContentPage.aspx will be looking for /Folder1/Site.css
If you change your stylesheet to using <link rel="Stylesheet" type="text/css" href="/Site.css" /> Then your website will look for the stylesheet in the root directory. HOWEVER, if your website is running as
`http://localhost:1234/WebsiteFolder/ContentPage'
"WebsiteFolder", then having /Site.css will look for the css file outside of the "WebsiteFolder"
Please post the folder structure of your site, also whether your site is running with a Virtual Path. To find the Virtual Path, view the properties for the website.
use
<link href="~/Site.css" runat="server" id="link1" rel="stylesheet" type="text/css" />
instead of
<link href="Site.css" rel="stylesheet" type="text/css" />
after that css loads properly and works fine....