I've never used either of these 2 controls before and I'm stuck with no visible rendering of the page (compiles and runs but produces nothing); I have no code behind file with this simple asp.net page and I am using Visual Studio 2008:
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="Index.aspx.cs" Inherits="zList.Index" %>
<!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>
<asp:ListView ID="CategoryList" runat="server"
DataSourceID="Categories">
<LayoutTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemPlaceholder">
</asp:PlaceHolder>
</ol>
</LayoutTemplate>
<ItemTemplate>
<li><%# Eval("AttrDesc")%></li>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
<asp:sqldatasource runat="server" id="Categories"
ConnectionString="<%$ ConnectionStrings:ZIPeeeConnectionString2 %>"
SelectCommand="SELECT AttrID,AttrDesc FROM dbo.tblAttributes1">
</asp:sqldatasource>
Here is the connection string section from web.config (I have tried both connection strings separately and they both result in nothing rendered):
<connectionStrings>
<add name="ZIPeeeConnectionString" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ZIPeeeConnectionString2" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;User ID=sa;Password=" providerName="System.Data.SqlClient"/>
</connectionStrings>
I am getting no runtime errors and no errors during the build. The simple query works fine from SQL Query Analyzer (i.e. SQL Server 2000). Any ideas?
EDIT-UPDATE:
Here is what I have in my .ASPX.CS code behind file and I cannot get the debugger to stop on the breakpoint on the .DataBind method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace zList
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CategoryList.DataBind(); // breakpoint set here but debugger won't stop here
}
}
}
By the way, I fired up SQL Profiler and it appears the SQL select is not even being fired against
the server. As I said, the page is empty - just this junk when I scrape it via View Page Source:
<!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><title></title></head>
<body>
<form name="form1" method="post" action="Index.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjAyMTkwMzQ3OQ9kFgQCAw9kFgICAQ8UKwACDxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50Av////8PZGRkAgUPD2QPEBYDZgIBAgIWAxYCHg5QYXJhbWV0ZXJWYWx1ZWQWAh8CZBYCHwJkFgMCAwIDAgNkZBgBBQxDYXRlZ29yeUxpc3QPZ2TCuhjvuwDRjaGJssTwiDXpAv/fdw==" />
</div>
<div>
</div>
</form>
</body>
</html>
I think the only thing wrong with this code is the placement of the sqldatasource. Can you place it inside the tag.
If that doesnt work, can you change your listview definition to
<asp:ListView ID="CategoryList" runat="server">
and then change your page load code to
CategoryList.DataSource = Categories;
CategoryList.DataBind();
You should be able to hit the debugger
As a last option, can you also check whether the connectionstrings is placed within the Configuration tag in web.config.
Related
I am receiving the below error from a very simple web application ran directly from Visual Studio 2010 with framework 4.0.
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot
be used in a cluster.
Here is my application files
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--<machineKey validationKey="08367F8C07194695F9714CB86778E9031DFAC34ECAE8DE9944CE7E765EB8B6F56D0DDE9C95639F01DF94597D4FFFF42BFCDB0A71544755C70683D6B95D3D3E5B" decryptionKey="DF5FA3F9EA83B31D9BF1381539CD90E3D4AEA74FEE490E5C1B0A160A4CCA7DA2" validation="SHA1" decryption="AES" />-->
<pages enableViewState="false"></pages>
</system.web>
</configuration>
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test.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></title>
</head>
<body>
<form id="form1" runat="server" method="post" action="info.aspx">
<div>
<input type="hidden" name="data" value="this is post data" />
<input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>
info.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class info : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string x = Request.Form["data"];
}
}
}
I tried all possible solutions given over internet but in vain.
Added machine key {not worked}
Added enableViewState="false" {not worked}
I am desperately trying to understand why this behaviour?
Have you tried using ASP.net proper hidden as opposed to input?
<asp:HiddenField ID="data" value="this is post data" runat="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....
I have to use a ckeditor in my application but I dont know how to write the
# Register Assembly="" Namespace="" TagPrefix="" %>
From where I could get the assembly?
In web.config section you can write:
<add tagPrefix="FredCK" namespace="FredCK.CKEditor" assembly="FredCK.CKEditor, Culture=neutral, PublicKeyToken=9ef91de3e191403a" />
Actually, best is not to use the ASP.NET CKEditor control but use CKEditor directly. The control is outdated (version 3.6 instead of 4.1) and not necessary. Basically, use a multiline textbox and make it of the class CKEditor. Don't forget to add the ckEditor.js to the head section:
web.config
<configuration>
<system.web>
<httpRuntime requestValidationMode="2.0"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
Test.aspx
<!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>ckeditor test page</title>
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:TextBox class="ckeditor" ID="CkeditorTextBox" runat="server" TextMode="MultiLine" Columns="80" Rows="10">
Hi
</asp:TextBox>
</p>
<p>
<asp:Button ID="SubmitButton" runat="server" onclick="SubmitButton_Click" Text="Submit" />
</p>
</form>
</body>
</html>
Test.aspx.cs
using System;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SubmitButton_Click(object sender, EventArgs e) {
string CkEditorText = CkeditorTextBox.Text;
//add some processing here
}
}
There is a nice asp.net wrapper control for the ckeditor: http://cksource.com/forums/viewtopic.php?f=11&t=15882
The answer will be
scrpt type = "text/javascript" src = "ckeditor/ckeditor.js"....close script
//ckeditor is the folder that you have created in your application.
script type="text/javascript"
window.onload = function()
{
debugger
vartxtDemo = document.getElementByID('<%txtDemo.ClientID%');
CKEDITOR.replace(txtDemo);
}...//close the script
but before that make a ckeditor folder in your application and paste the contents that you have downloaded,
Is SearchString acting as property of Page class?
Here is code,
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public string SearchString
{
get { return txtSearch.Text; }
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Button Search Typed</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblSearch"
Text="Search:"
Runat="server" />
<asp:TextBox
id="txtSearch"
Runat="server" />
<asp:Button
id="btnSearch"
Text="Go!"
PostBackUrl="ButtonSearchResultsTyped.aspx"
Runat="server" />
</div>
</form>
</body>
</html>
It is a property of your page class. This is not the page class. Your class inherits from the main page class.
Also, you need to be careful how you use thist kind of thing. Remember, ASP.Net pages are stateless, just like with other platforms. That means every time you do a postback, including just to handle simple server events like button clicks, you are working with a new instance of the class. Any previous SearchString value was lost.
It's a property of the class generated for your ASPX file, which inherits from System.Web.UI.Page. It's not added to that class itself, of course.
I have that works fine without Script manager. but if I add script manager that getting an error: sys undefined.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Block-ui-pageload.aspx.cs" Inherits="Block_ui_pageload" %>
<%# Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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></title>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.blockUI.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="divConfirmBox1">
<asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Category Name">
<ItemTemplate>
<asp:Label ID="lblCategoryName" runat="server" Text='<%# Eval("CategoryName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<input type="button" value="Delete" onclick="showDeleteConfirmation('<%# Eval(" CategoryId")=CategoryId") %=% />')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div id="divConfirmBox" style="display:none">
Are you sure you want to delete this record?
<input type="button" value="No" />
</div>
</div>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
$(function () {
$('#divConfirmBox1').block({ message: $('#divConfirmBox') });
});
$(function () {
$('#divConfirmBox').click(function (event) {
$('#divConfirmBox1').unblock();
});
});
</script>
initially during the page load . I am blocking the screen(PAge). once the user clicks the button the page is unblocked.
is there anything wrong in the Syntax whiling working with Ajax script manager
You should move the jQuery code into $(document).ready. I suspect you're preventing certain scripts from loading appropriately by running the code inline rather than in .ready. I'm running the same version of jQuery (but not UI block) with ScriptManager in 3.5 right now, no prob.
AJAX is not a thing - its a bunch of technologies put together to achieve asynchronous communication. Yes, you have some JavaScript coding in there, but none of them actually do anything 'ajaxian' - a good example of something really AJAX-style would be an validation of a (registration) form or something like that. You'd set some oberservers for some fields and validate them whilst the user is still making inputs on other fields...
I think what you're looking for is noConflict. It's been a while since I've used asp.net ajax but if I'm not mistaken, there is a $ function defined.
In the web.config we need to add the follwing code within tag.
then the problem was solved
every thing was working fine