problems when adding server side control - asp.net

I have a fully HTML project, with complete .CSS file.
The thing is I want to add some asp.net controls like TextBox's and Buttons and what not, but when I add server side controls to it and run the pages it gave me errors I cannot follow because it appears on the tab of the browser.
The error start with control 'txt' of type TextBox..., and then it gives me Navigation Cancelled, and the browser direct me to
http://youtubedownloader.mybrowserbar.com/cgi/errors.cgi?q=http://localhost:55942/Dar%2520Al-Thaqafah/Default2.aspx&type=dns&ISN=A9B31DEE919345BE838EAF628EAFA22F&ccv=149&cnid=937811&cco=US&ct=1&sc=500
Here is the code of default2.aspx page
[%# Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %]
[div class="header"]
[div class="logo"></div]
[div id="menu"]
[ul]
[li class="selected"][a href="Default.aspx"]Home[/a][/li]
[li][a href="Default2.aspx"]Available Books[/a][/li]
[li][a href="Default3.aspx"]Register[/a][/li]
[li][a href="Default4.aspx"]Checkout[/a][/li]
[li][asp:TextBox ID="txt" runat="server"][/asp:TextBox][/li]
[li][asp:Button ID="btn" Text="hhhhh" runat="server" /][/li]
[/ul]
[/div]
[/div]
[/div]
I am using Browser IE version 9.
Visual Studio 2005.
Thank you

Try with the code given below:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div class="logo"></div>
<div id="menu">
<ul>
<li class="selected">Home</li>
<li>Available Books</li>
<li>Register</li>
<li>Checkout</li>
<li><asp:TextBox ID="txt" runat="server"></asp:TextBox></li>
<li><asp:Button ID="btn" Text="hhhhh" runat="server" /></li>
</ul>
</div>
</form>
</body>
</html>

Well with the limited information you provided, I guess the problem is that you are adding ASP.NET controls to an HTML page and not an ASP.NET page and that's why you see the errors. The ASP.NET controls are executed by the server and converted into Browser-readable HTML controls. So, you can only add ASP.NET controls to only ASP.NET page.

Related

Why is an added web form different from the default forms?

An ASP.NET Webforms project has some default pages ("About" and "Contact" to be specific), which have this type of content:
<%# Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%: Title %>.</h2>
<h3>Your application description page.</h3>
<p>Use this area to provide additional information.</p>
</asp:Content>
Yet when you select Add > Web Form, it creates this:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="DuckbilledPlatypus.aspx.cs" Inherits="DuckbilledPlatypus" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Why the difference/inconsistency? Note: This is in Visual Studio 2013; I'm not positive other versions are the same.
You didn't create the Web Form using the Master Page. When you right click the project, click Add Item, then under Web it will have Web Form and then other classes as well. Using the Web Form using Master Page should give you the one that you want. The one that it sounds like you used is the blank web form and has no site.master linked up to it where the Web Form using Master Page links up the site.master for you.

"Content Not Supposed to Be Outside 'Script' or 'asp:Content' Regions"

I'm starting to learn ASP.NET and it's the little things that are really annoying with Visual Studio Web Dev Express. I keep getting the error "Content Not Supposed To Be Outside 'Script' or 'asp:Content' Regions" - so I put content inside an asp:content container and it doesn't disappear. I also get the same sort of error with declaring the DocType. Any suggestions to fix this. Also on an off-note: is there any better IDE's to code ASP.NET?
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Hello VS2010</title>
</head>
<body>
<asp:content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1" runat="server">
Hello World
</asp:Literal>
</div>
</form>
</asp:content>
</body>
</html>
Master Page
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ Log In ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
Master pages are a kind of template applied to all of your pages. Here it seems you use one without knowing it
MasterPageFile="~/Site.master"
In the masterPage you have all the content you want to be common to all your pages and a asp:content region where you can add content for each page.
So here you can try to remove the masterPage reference or just Adding and removing things in the asp:content region.
Here's the msdn link about MasterPages. I think it really necessary to understand masterPages to learn asp.net.
New Reply:
Well, okay.
So first things first only one form tag per page, that includes pages within master pages.
You don't need the form tag or the html, body or head tag on your Web form, only your master page.
So Page.aspx code should be like: http://codepaste.net/87n474
Note you need to include all content areas in your aspx page that are available in your master page.
Original Reply:
Couple of things.
Check your masterpage layout and see if there is any content misplace in that. (paste it here as well)
Also related to your masterpage, I don't see much point in having a masterpage if you're putting all your HTML markup inside the asp.aspx page.
Your doctype should be:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Note the small differences in capitalisation.
Finally, the only IDE any better than web dev express is the full version of Visual Studio, there isn't any better version for creating and debugging asp.net sites than the latest version of visual studio.

Events only firing on specific machines but not on others

I have been trying to solve this problem for several weeks now and it is getting really frustrating. Basically i have a simple project which includes one master page and one content page. the following code is what is found in the content page
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="ButtonContent"
onclick="Button1_Click" />
</asp:Content>
The button is bound to a simple event. A break point is set to detect whether the event fired as expected. The event does not fire when a form is placed above the content place holder.
<%# 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>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<form></form>
</div>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div>
</div>
</form>
</body>
</html>
however the event is fired when the form is removed or place below the content place holder. On the other hand, on some machines i have found that it does not matter if a form is placed before the content place holder. I have tried this project on 4 machines (three windows 7 and one xp) it has worked regardless of form placement on two machines and has been subject to form placement on the other two.
Could some one please point me to some setting which could solve this problem or offer any advice to solve my problem. I need a form before the content place holder so removing is out of the question. It would also make sense that some sort of setting is preventing the project from working correctly on another machine
per HTML spec, you can not have form inside form. If I remember correctly some browsers break when you have this kind of structure. I think IE works fine.
If you need another form, put it outside of the <form id="form1" runat="server">
- above it, specifically. That is valid.

ASP.NET control for reCAPTCHA not working in Opera

I use ASP.NET reCAPTCHA control on my website (.net 3.5). I got it from this site (version 1.0.4.0).
It works great in IE6, Chrome, Firefox, and Safari, but I don't know why it doesn't work in Opera. When I open the page, it's blank. I use Opera 10.62.
I've prepared just a simple web form which contains only the reCAPTCHA control. The markup is:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ClientWebPortal.test" %>
<%# Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<!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">
<div>
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="xxxxx"
PrivateKey="xxxxxxxx" />
</div>
</form>
</body>
</html>
Anybody have any suggestions?
I have experienced the same problem it appears to be a JavaScript exception that causes the image not to load in Opera. Below is the exception that I get:
Uncaught exception: [object DOMException]
Error thrown at line 12, column 0 in https://www.google.com/recaptcha/api/challenge?k=6LtestSAAAAAM1MsYg9ktesttestt9niYAftest:
document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

ASP.NET MasterPageFile causing error

I'm trying to use a master page in my website. I created a page and then created the master. I then added the tag MasterPageFile="~/master". I'm guessing that I need to do something to my main page, because I've now started getting the error:
The page contains markup that is not valid when attached to a master page
My main page is as follows:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/my.master" %>
<!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">
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
I tried deleting the tag thinking that this might be the issue. Can anyone point me in the right direction?
You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders. See the msdn page on this topic.
Quoted from that link above, your master page could contain the following:
<td><asp:contentplaceholder id="Main" runat="server" /></td>
Which the content page would fill by supplying the following
<% # Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
Note that I included the main declaration at the top of the content page.
the pages inhering master page should have a <asp:Content as their root. this means no html tag no doctype etc.

Resources