Click Event For Cross Page PostBack - c#

I have a Search.aspx page with TextBox and Button. The postback is to Results.aspx which has a GridView. The Sql query works as I have checked it with QueryDesigner.
In theory, a pseudo-search should be done by typing a value into the text box and clicking the button. When I enter a value and click, the Results.aspx page opens but is blank.
The click event in the Search.aspx is nothing more than:
protected void Button2_Click(object sender, EventArgs e){}
This setup does work in a Web Project, however, will not in a Web Site, which this is. It would appear that the click event is not working by not submitting the value to the Results.aspx page. I have had no luck finding a click event which will work. I would appreciate any help.
EDIT: The sql query is complicated but as I said, it works fine when a value is entered in the Query Designer. I did add a "namespace" to the .cs as Web Sites, as opposed to Web Projects, normally do not have a namespace.
Search.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="LinqTest.Search" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" 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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="Name"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" PostBackUrl="~/Results.aspx" />
</div>
</form>
</body>
</html>
Search.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LinqTest
{
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
ResultsSearch.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ResultsSearch.aspx.cs" Inherits="RecipeFaire.ResultsSearch" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%# PreviousPageType VirtualPath="~/Search.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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- this is the results of the search done on the search.aspx -->
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="RecipeID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<tr>
<td rowspan="2">
<asp:Image ID="Image1" runat="server" Width="100px" Height="80px" ImageUrl='<%# "~/Handler.ashx?RecipeID=" + Eval("RecipeID")%>' />
</td>
<td rowspan="2" width="100px">
<asp:Rating ID="Rating1" runat="server" align="right" valign="top" CurrentRating='<%# Eval("RatingAVG")%>'
MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar">
</asp:Rating>
&nbsp&nbsp&nbsp<br></br>
<asp:Label ID="Label7" runat="server" align="right" Text='<%# Eval("Count") %>' />&nbsp&nbsp
<asp:HyperLink ID="Home" Font-Size="Small" runat="server" NavigateUrl='<%# Bind("RecipeID", "../../Comments.aspx?RecipeId={0}") %>'
Text="Reviews" />
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Bind("RecipeID", "PageLinkDetails.aspx?RecipeId={0}") %>'
Text='<%# Eval("RecipeName") %>'></asp:HyperLink>
</td>
</tr>
<tr style="width: 500px">
<td>
<asp:Label ID="DescriptionLabel" valign="top" runat="server" Text='<%# Eval("Description") %>' />
</td>
</tr>
<tr>
<td colspan="5" style="color: LightGrey">
<asp:Label ID="Label2" runat="server" Font-Size="1px" Height="1px" Text='<%# Eval("RecipeID") %>'></asp:Label>
<hr style="border-style: dotted" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<asp:LinkButton
runat="server" ID="SortByName" CommandName="Sort" CommandArgument="RecipeName">Sort By Recipe Name</asp:LinkButton>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<asp:LinkButton runat="server" ID="SortByPrice" CommandName="Sort" CommandArgument="RatingAVG">Sort By Rating</asp:LinkButton>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="" align="center">
<asp:DataPager ID="DataPager2" PagedControlID="ListView1" PageSize="8" runat="server">
<Fields>
<asp:NumericPagerField ButtonCount="8" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RecipeUploadConnectionString %>"
SelectCommand="SELECT pr.RecipeID, pr.CategoryName, pr.CategoryType, pr.RecipeName, pr.Description, COUNT(rr.RecipeID) AS Count, AVG(rr.Rating) AS RatingAVG
FROM PostedRecipes AS pr LEFT OUTER JOIN RecipeRatings AS rr ON pr.RecipeID = rr.RecipeID
WHERE pr.RecipeName LIKE '%' + #RecipeName + '%' OR pr.CategoryName LIKE '%' + #CategoryName + '%'
OR pr.CategoryType LIKE '%' + #CategoryType + '%' OR pr.CuisineOrigin LIKE '%' + #CuisineOrigin + '%'
OR pr.CuisineType LIKE '%' + #CuisineType + '%' GROUP BY pr.RecipeID, pr.RecipeName, pr.CategoryName, pr.CategoryType, pr.CuisineOrigin, pr.CuisineType, pr.Description">
<SelectParameters>
<asp:FormParameter FormField="RecipeName" Name="RecipeName" Type="String"/>
<asp:FormParameter FormField="CategoryName" Name="CategoryName" Type="String" />
<asp:FormParameter FormField="CategoryType" Name="CategoryType" Type="String"/>
<asp:FormParameter FormField="CuisineOrigin" Name="CuisineOrigin" Type="String" />
<asp:FormParameter FormField="CuisineType" Name="CuisineType" Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
ResultsSearch.cs
using System;
using System.Data;
using System.Data.SqlClient;
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 System.IO;
using System.Text;
using System.Web.SessionState;
namespace RecipeFaire
{
public partial class ResultsSearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}

i am seeing something weird...
in your search.aspx... you have this.
<asp:Button ID="Button1" runat="server" Text="Search" PostBackUrl="~/Results.aspx" />
However, in your 2nd page listing... you posted this...
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ResultsSearch.aspx.cs" Inherits="RecipeFaire.ResultsSearch" %>
the PostbackUrl is Results.aspx and the other page you posted in ResultsSearch.aspx.
Can you check if this is the problem? (i cant post comments yet.)

You definitely aren't showing us all of your code-behind, but we'll assume you are doing this somewhere:
ListView1.DataSource = SqlDataSource1;
ListView1.DataBind();
After you've done that, THEN you can find the Label and set its text (do not do this in the Page_Load prior to binding).
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label recipeName = (Label)e.Item.FindControl("labRecipeName");
recipeName.Text = Request.QueryString["RecipeName"].ToString()
}
}
To use a querystring value for your SqlDataSource, use a QueryStringParameter:
<SelectParameters>
<asp:QueryStringParameter Name="RecipeName" QueryStringField="RecipeName" Type="String" />
</SelectParameters>

Related

Display data from List<string> to asp:repeater with some step

everyone!
I'm new in ASP.net dev, and I'v faced with next problem
I need to display data from List to ASP.Net page with asp:repeater with step i=i+3, but i can't use index with Container.Dataitem and repeaterId.Items.Count always is 0
I need something like that:
<itemtemplate>
<tr>
<td>
i
</td>
<td>
i+1
</td>
<td>
i+2
</td>
</tr>
</itemtemplate>
All data is type of string. I hope, that someone help me with my problem.
test this:
HTML(.aspx) FILE
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
* {font: 8pt tahoma;}
table {border-collapse:separate;border-spacing:5px;}
table td {border:solid 1px #14c739;padding:5px}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater runat="server" ID="rpt_demo">
<HeaderTemplate>
<table>
<tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<%# Container.ItemIndex + 1 %>- <%# Container.DataItem %>
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
CodeBehind File
List<String> lst_Demo = new List<string>();
lst_Demo.Add("No.1");
lst_Demo.Add("No.2");
lst_Demo.Add("No.3");
lst_Demo.Add("No.4");
lst_Demo.Add("No.5");
lst_Demo.Add("No.6");
lst_Demo.Add("No.7");
lst_Demo.Add("No.8");
rpt_demo.DataSource = lst_Demo;
rpt_demo.DataBind();

Accessing ListView Evals from code behind. getting Object reference not set to an instance of an object

Like many other people I am trying assign an Eval value to a label in a table outside of a ListView. I am using a stored procedure that returns monthly rainfall amounts for sites throughout the city. The field I want is not one of the passed parameters: #reqyear and #reqLocation. It is a calculated field, Total, which shows up fine in the ListView as a Eval, but I cannot figure out how to access it directly in code behind so I am using an ItemDataBound method to find the control then assign it. Several snipets are readily found in the boards. So I tried each one that seemed applicable and all return an "Object reference not set to an instance of an object" error. I am trying to assign Eval("Total") to the label id MTotal. The page runs fine without the code needed for label assignment. Perhaps, I am going about the label assignment the wrong way and can get the field I want without using the Eval in the ListView.
Any advice is appreciated.
code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace WebApplication1.OUTREACH.rainfall
{
public partial class monthlyRF : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
reqyear.Items.Clear();
for (int i = DateTime.Now.Year; i != 1998; i--)
{
reqyear.Items.Add(i.ToString());
}
reqLocation.SelectedValue = "2";
}
String strConnString = WebConfigurationManager.ConnectionStrings["TelogerConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "dbo.spBWSC_GetTrendDataMonthly";
cmd.Parameters.Add("#req_Location", SqlDbType.VarChar).Value = reqLocation.Text;
cmd.Parameters.Add("#req_year", SqlDbType.VarChar).Value = reqyear.Text;
cmd.Connection = con;
try
{
con.Open();
ListView1.DataSource = cmd.ExecuteReader();
ListView1.DataBind();
yearLabel.Text = reqyear.Text;
switch (cmd.Parameters["#Req_Location"].Value.ToString())
{
case "2":
site_nameLabel.Text = "Union Park";
break;
case "3":
site_nameLabel.Text = "Roslindale";
break;
case "4":
site_nameLabel.Text = "Dorch-Adams";
break;
case "5":
site_nameLabel.Text = "Allston";
break;
case "6":
site_nameLabel.Text = "Charlestown";
break;
case "7":
site_nameLabel.Text = "Longwood";
break;
case "8":
site_nameLabel.Text = "Hyde Park";
break;
case "9":
site_nameLabel.Text = "Dorch-Talbot";
break;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label Total_lbl;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Total_lbl = (Label)e.Item.FindControl("Total_lbl");
DataRowView rowView = e.Item.DataItem as DataRowView;
string sTotal = rowView["Total"].ToString();
MTotal.Text = sTotal;
}
}
}
}
ASPX:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="monthlyRF.aspx.cs" Inherits="WebApplication1.OUTREACH.rainfall.monthlyRF" enableEventValidation="false" EnableViewState="true" %>
<!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">
<asp:RadioButtonList ID="reqLocation" runat="server" Font-Italic="False"
Height="100px" RepeatColumns="4" RepeatDirection="Horizontal" Width="590px">
<asp:ListItem Value="2">Union Park</asp:ListItem>
<asp:ListItem Value="3">Roslindale</asp:ListItem>
<asp:ListItem Value="4">Dorch-Adams</asp:ListItem>
<asp:ListItem Value="5">Allston</asp:ListItem>
<asp:ListItem Value="6">Charlestown</asp:ListItem>
<asp:ListItem Value="7">Longwood</asp:ListItem>
<asp:ListItem Value="8">Hyde Park</asp:ListItem>
<asp:ListItem Value="9">Dorch_Talbot</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="reqyear" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TelogerConnectionString %>"
SelectCommand="spBWSC_GetTrendDataMonthly" SelectCommandType="StoredProcedure" >
<SelectParameters>
<asp:ControlParameter ControlID="reqyear" Name="req_year"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="reqLocation" Name="req_Location"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<table border="1" cellpadding="4" cellspacing="0" width="590px" style="margin-top: 25px;">
<tr>
<td><asp:Label ID="site_nameLabel" runat="server" />
</td>
<td style="text-align:right;"><asp:Label ID="yearLabel" runat="server"/>
</td>
</tr>
</table>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="site_name, Total, month, monthly_total" OnItemDataBound="ListView1_ItemDataBound">
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="border: 1px solid black;" >
<td style="width:245px;">
<asp:Label ID="Total_lbl" runat="server" Text='<%# Eval("Total") %>' /></td><td><asp:Label ID="monthLabel" runat="server" Text='<%# Eval("month") %>' />
</td>
<td style="text-align:right; width:245px;">
<asp:Label ID="TotalLabel" runat="server" Text='<%# Eval("monthly_total", "{0:0.00}") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" width="590px">
<tr id="header1" runat="server" style="">
<th style="text-align:left;" runat="server">
Month</th>
<th style="text-align:right;" runat="server">
Rainfall (in.)</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
</td>
</tr>
<tfoot>
<tr >
<td colspan="2">this is the listview footer</td>
</tr>
</tfoot>
</table>
</LayoutTemplate>
</asp:ListView>
<table border="1" cellpadding="4" cellspacing="0" width="590px" style="margin-top: 0;">
<tr>
<td>first cell
</td>
<td style="text-align:right;"><asp:Label ID="MTotal" runat="server" Text="Label"/>
</td>
</tr>
</table>
</form>
</body>
</html>
I'd suspect that the line
DataRowView rowView = e.Item.DataItem as DataRowView;
is the problem here. Set a breakpoint on that line and investigate what type you are getting there.
Where type conversion is done using the as keyword, a failure to carry out the conversion will return null rather than an exception, so the subsequent call to the ["Total"] indexer is being carried out on a null reference.

How to get web user control's text box value using javascript

I am developing an calendar user control using Ajax calendar extender.
User control code
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" ClientIDMode="Predictable" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControl" %>
<link rel="stylesheet" href="GridViewCSSThemes/YahooGridView.css" type="text/css" media="screen" />
<div style="position:relative;border:none;">
<asp:TextBox ID="txtDate" MaxLength="10" ToolTip="DD/MM/YYYY" Width="100"
CssClass="tb10" runat="server">
</asp:TextBox>
<asp:ImageButton ImageUrl="~/GridViewCSSThemes/Images/Calendar_scheduleHS.png" ID="imgCalender" runat="Server"
BorderWidth="0" ImageAlign="absmiddle" />
<ajaxControl:CalendarExtender ID="AjaxCalenderCtrl" runat="server" Format="dd/MM/yyyy" PopupPosition ="TopLeft"
TargetControlID="txtDate" CssClass="red" FirstDayOfWeek="Sunday" PopupButtonID="imgCalender">
</ajaxControl:CalendarExtender>
<ajaxControl:TextBoxWatermarkExtender WatermarkCssClass="tb10" ID="txtWaterMarkDate"
runat="server" WatermarkText="DD/MM/YYYY" TargetControlID="txtDate">
</ajaxControl:TextBoxWatermarkExtender>
<ajaxToolkit:MaskedEditExtender ID="MaskedEdit_dt" runat="server"
TargetControlID="txtDate"
Mask="99/99/9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Date"
AcceptAMPM="true"
AcceptNegative="Left"
ErrorTooltipEnabled="True" />
<ajaxToolkit:MaskedEditValidator ID="MaskedEditV_dt" runat="server"
ControlExtender="MaskedEdit_dt"
ControlToValidate="txtDate"
EmptyValueMessage="Date is required"
InvalidValueMessage="Date is invalid"
Display="Dynamic"
TooltipMessage="Input a date"
EmptyValueBlurredText="Date is required"
InvalidValueBlurredMessage="Date is invalid"
IsValidEmpty="false"
ValidationGroup="MKE" />
<%--<asp:RegularExpressionValidator ID="regexpvalEndDateEdit" ErrorMessage="!" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d"
ControlToValidate="txtDate" runat="server"></asp:RegularExpressionValidator>--%>
</div>
Code behind user control
internal string _DValue;
public string DValue
{
get
{
if (_DValue == "")
{
_DValue = txtDate.Text;
}
else
{
txtDate.Text = _DValue;
}
return _DValue;
}
set { _DValue = value; }
}
public string IdClientId
{
get { return this.ClientID; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
I am able to get controls value using server side code.
Now i need to access text-box(txtDate) value and MaskedEditValidator(MaskedEditV_dt) inerHtml from javascript.
How can i do this.
Edit-1
User control in aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeFile="CustomControlTest2.aspx.cs" Inherits="CustomControlTest2" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControl" %>
<%# Register TagPrefix="uc1" TagName="UCCalender" Src="~/WebUserControl.ascx" %>
<!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>User Control Test</title>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true" />
<div>
<table>
<tr>
<td>
<uc1:UCCalender ID="UCCalStartDate" runat="server" DValue="" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnExe" runat="server" Text="Submit" onclick="btnExe_Click" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblMsg" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
Code behind
protected void btnExe_Click(object sender, EventArgs e)
{
lblMsg.Text = UCCalStartDate.DValue;
}
ASP.NET loads to display the UserControl, it ONLY renders the contents of the UserControl. The Controls in the usercontrol will rendered with the ID as $content_UControlName_Control. You can check this after the rendering the page. You can access the contol using that ID from Javascript like document.getElementById(content_UControlName_Control).
Finally i got answer. Thanks to Nag
On button click
<asp:Button ID="btnExe" runat="server" Text="Submit" OnClientClick="getValue('UCCalStartDate_txtDate','UCCalStartDate_MaskedEditV_dt');" onclick="btnExe_Click" />
Javascript
function getValue(id,msk) {
alert(document.getElementById(id).value);
alert(document.getElementById(msk).innerHTML);
}
Finaly i am able to access calander control's text-box value using java-script

The name 'grdUserActivity' does not exist in the current context

I have a grid that is named grdUserActivity. I'm not sure what the error means.
The name 'grdUserActivity' does not exist in the current context
C#
public partial class frmViewPersonnel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Declares the DataSet
dsUserActivity myDataSet = new dsUserActivity();
// Fill the dataset with what is returned from the function
myDataSet = clsDataLayer.GetUserActivity(Server.MapPath("PayrollSystem_DB.mdb"));
// Sets the DataGrid to the DataSource based on the table
grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"];
// Binds the DataGrid
grdUserActivity.DataBind();
}
}
}
.ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="frmPersonnel.aspx.cs" Inherits="frmPersonnel" %>
<!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 align="center">
</div>
<asp:Panel ID="Panel1" runat="server" Height="250px" HorizontalAlign="Left"
Width="300px">
<asp:Label ID="Label1" runat="server" Text="First Name:" Width="80px"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Last Name:" Width="80px"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Pay Rate:" Width="80px"></asp:Label>
<asp:TextBox ID="txtPayRate" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label4" runat="server" Text="Start Date:" Width="80px"></asp:Label>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label5" runat="server" Text="End Date:" Width="80px"></asp:Label>
<asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server"
PostBackUrl="~/frmPersonnalVerified.aspx" Text="Submit"
onclick="btnSubmit_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
<br />
<asp:Label ID="lblError" runat="server"></asp:Label>
</asp:Panel>
</form>
Not sure if this is a type-o
But your aspx file is pointing to frmUserActivity rather than frmViewPersonnel
<%# Page Language="C#" AutoEventWireup="true" CodeFile="frmUserActivity.aspx.cs" Inherits="frmUserActivity" %>
So either you are editing the wrong .cs file, OR the wrong .aspx file ;)
EDIT
After seeing your edits, your frmUserAcitivty aspx page does not contain the grdUserActivity control. So of course it wont be found.

asynccontrols asp.net Error Creating Control " Object reference not set to an instance of an object"

here is my sample form.
I'm using asynccontrols
. Site compiles fine, loads fine, works fine. Can't view anything in designer. Halp?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Calendar2.aspx.cs" Inherits="txssaAuction.Calendar2" %>
<%# Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls" TagPrefix="dw" %>
<!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>
<dw:asynccalendar runat="server" ID="calMain"
DefaultStyle="false"
AbbreviateDays="true"
PreviousMonthText="<div class='navPrev' title='Previous Month'><<<</div>"
NextMonthText="<div class='navNext' title='Next Month'>>>></div>"
SelectedDayCssClass="selDay"
CssClass="asyncCalReg"
WeekendDayCssClass="weekend"
OtherMonthCssClass="otherMonth"
DayCssClass="calday"
Width="500"
MonthListCssClass="monthList"
YearListCssClass="yearList"
TodayCssClass="today"
TodayFooterCssClass="todayFooter"
DaySelectionMode="Multiple"
OnDaySelected="calMain_DaySelected"
MonthSelectorCssClass="monthSelector"
YearSelectorCssClass="yearSelector" />
<p>
<dw:asynclistbox runat="server" ID="lstMain"
SelectionMode="Single"
OnSelectedIndexChanged="lstMain_IndexChanged"
Rows="7">
<AsyncListItem Text="No Selected Dates" Value="none" />
</dw:asynclistbox>
<br/>
<dw:asynclinkbutton runat="server" ID="lnkMain"
ConfirmMessage="Are you sure you want to clear all selected dates?"
OnClick="lnkMain_Click">Clear Selected Dates</dw:asynclinkbutton>
</p>
</p>
<dw:AsyncRepeater ID="rptUsers" runat="server"
OnItemDataBound="rptUser_ItemDataBound"
EnableEffects="true"
RollACssClass="rollA"
RollBCssClass="rollB"
HighlightCssClass="highlight"
CssClass="asyncRep"
Visible="true">
<HeaderTemplate>
<table cellpadding="4">
<tr class="headlnk">
<td>
First Name
</td>
<td>
Last Name
</td>
<td>
Account Balance
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr $roll$ $highlight$>
<td>
<dw:AsyncLiteral runat="server" ID="ltlFirstName" />
</td>
<td>
<dw:AsyncLiteral runat="server" ID="ltlLastName" />
</td>
<td>
<dw:AsyncLiteral runat="server" ID="ltlAccBalance" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</dw:AsyncRepeater>
<br />
<dw:AsyncButton runat="server" ID="btMain"
OnClick="btMain_Click"
CssClass="greyButton">Re-Bind the AsyncRepeater</dw:AsyncButton>
</div>
</form>
</body>
</html>

Categories