Inheriting From DataSourceControl Doesn't Produce IDataSource
Feb 15, 2010
I am trying to create a custom datasource control. I have been following this article to the letter (I think...). I have a skeleton / basic implementation of my datasource, however when I declare it in the markup and try to statically bind it to a gridview, I receive the following error:
The DataSourceID of 'grdVw' must be the ID of a control of type IDataSource
This seems extremely strange to me, since my datasource inherits from DataSourceControl, which in turn implements IDataSource. Even if I explicitly implement IDataSource in my custom datasource, it makes no difference. My Markup is:
<DataBrokerDataSource ID="objSrcDBroker" runat="server" />
<div>
<asp:GridView ID="grdVw" DataSourceID="objSrcDBroker" DataMember="Table0" runat="server">
</asp:GridView>
</div>
<div>
<asp:GridView id="grdVw2" DataSourceID="objSrcDBroker" DataMember="Table1" runat="server">
</asp:GridView>
</div>
And my control is:
Public Class DataBrokerDataSource
Inherits DataSourceControl
Implements IDataSource 'Have tried with this statement included AND excluded = same result
Protected Overrides Function GetView(ByVal viewName As String) As System.Web.UI.DataSourceView Implements IDataSource.GetView
'Code here
End Function
Protected Overrides Function GetViewNames() As System.Collections.ICollection Implements IDataSource.GetViewNames
'Code here
End Function
End Class
Looking at the stack trace shows that the error originates at:
System.Web.UI.WebControls.DataBoundControl.GetDataSource().
I have examined this method in reflector (see below), looking at this (based on the error message that I am getting) it appears to me as though the FindControl part is succeeding but that the source = control as IDataSource; leaves source as a null value, i.e. the conversion fails - But Why?
protected virtual IDataSource GetDataSource()
{
if ((!base.DesignMode && this._currentDataSourceValid) && (this._currentDataSource != null))
{
return this._currentDataSource;
}
IDataSource source = null;
string dataSourceID = this.DataSourceID;
if (dataSourceID.Length != 0)
{
Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
if (control == null)
{
throw new HttpException(SR.GetString("DataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID }));
}
source = control as IDataSource;
if (source == null)
{
throw new HttpException(SR.GetString("DataControl_DataSourceIDMustBeDataControl", new object[] { this.ID, dataSourceID }));
}
}
return source;
}
View 1 Replies
Similar Messages:
Aug 11, 2010
I've reviewed a couple other sources and none seem to be complete, there is always a 'oh, ya, but you have to do this if you have this, or comments left about it not working etc... So this is my attempt to get a complete answer in one place. No datasourceControl, datasource being assigned programatically upon a button click event. My button click event that originally binds data to the gridview looks like this:
[Code]....
and of course the first code I try to implement the paging, doesn't work. Which is this:
[Code]....
the result is not an error, just an empty gridview. What am I missing? That's just an example of most of the examples out there saying how simple it is and you only need a few lines of code being wrong, or maybe not wrong, but incomplete. So I'm not going to even bother with the bidirectional sorting examples I came accross as there are usually comments about it not working, or not actually being bidirectional. I'm sure it is simple, once you actually have the information you need, getting that information is the harder part. So, anyone here care to take a shot at a complete example of implementing paging and bidirectional sorting on a gridview when not using a datasourceControl?
View 6 Replies
Nov 9, 2010
I created one stored procedure.
/*
SP Name :sp_Par_SearchCourseFinder
Author :Mr.Ravichandran
[code]...
View 1 Replies
Feb 11, 2011
I am trying to produce a DDL box with the following listing from a DB query.
13245
12345-
12346
12348
12348-R
Some 5 digit codes do not include a suffix in the record, the following query will only show the 5 digit codes with a suffix.
SELECT itemCode + '-' + itemSuffix AS code, keyID, itemCode, itemSuffix
FROM item
ORDER BY itemCode
How can I get the codes without a suffix to appear with the codes that have a suffix? The itemSuffix field in the DB is NULL for no data records.
View 3 Replies
Dec 2, 2013
I need to produce a simple graphic which is a simple rectangle (bar) with a variable portion filled in to denote a percentage.
What is the best way to achieve this? I had a look at the .net charting tools but the nearest I could find to what I needed was the barchart which didn't quite seem to meet my needs for a single value.
View 1 Replies
Dec 21, 2010
I've written a class that inherits from DataControlField. I did that so I can add a custom column to my gridview. The datasource of my gridview is a SQLDatasource. I now need to get the datatype of each field in my custom class e.g string, boolean, int etc.
View 7 Replies
Jan 10, 2010
I am trying to create BasePage Web.UI.Page that is inherited by my main page. But when i create public class mypage : BasePage method Page_Load of this class is not loaded in page live cycle. BasePage does not contain any Page_Load. has anybody got a clue where can be the problem?
View 5 Replies
Mar 30, 2010
I've written a ServerControl that contains a significant amount of javascript, and I'm using IScriptControl to pass parameters from the server code to the javascript. The javascript file is configured as an embedded resource, and a script reference to the file is being injected into the html by IScriptControl.GetScriptReferences(). The ServerControl is contained in a DLL assembly. When I use the control in a test page everything works fine.
What I want to do is to extend the control - to derive a new control from it, in a second assembly, that provides some extended functionality. (The first assembly contains code that is shared across customers, the second code that is shared across several projects for the same customer). So, my problem: I create a new ServerControl that derives from the first, but doesn't yet provide any new functionality.
[Code]....
Then I change my "<%@ Register ... %>" tag in the test page to reference the derived control. Things compile just fine, and the code-behind runs fine, but I get an undefined variable error in javascript. Sys.Application.add_init() is calling $create(), passing the <namespace>.<classname> of the javascript class, and it's throwing an error on the namespace.
Now, the namespace is registered on the first line of javascript file. Which makes it look like the javascript file might not be being included, when using the derived control. So I stuck a "debugging" line in front of the Type.registerNamespace(). Using the base control, the debugger breaks as it should. Using the derived control, it does not.
So, I look at the script includes in both versions of the page. They are identical. The sources are src="/testing/WebResource.axd?<random junk>", or src="/testing/ScriptResource.axd?<random junk", so I'm not sure which one refers to my embedded javascript file, but whichever one it is, the includes are identical between the page using the base control that works and the page using the derived control that does not.
View 1 Replies
Mar 3, 2010
I have a web user control, let's call it Control1.Control1 has a placeholder control in it defined in the Control1.ascx, and that placeholder control gets a bunch of controls connected to it dynamically at run time.I recently found the need to extend Control1, so I inherited from it. Now I have Control2 : Control1.
Control2 also has a placeholder control defined in it is aspx, Control2.ascx. However, when the Control2 class calls a member method of the base class, I find that the base class placeholder control goes out of scope and the member method tries to refer to the base classes placeholder (which, having never been initialized, is null).
How do I ensure that the two classes refer to a shared instance of the placeholder class?
View 3 Replies
Jul 5, 2010
Example site: [UL] In the left hand part of the page(refine result pane), how can I produce links/list like that? What control is used in that?? I know it has to use the data queried on the first page.
View 17 Replies
Jan 17, 2011
in the validation part.
Here goes the code:
[Code]....
At this particular part of the code:
[Code]....
I got 'Expression does not produce a value' in (ccJoin.ValidateCaptcha(tb_captcha.Text))
That code is used to validate and ensure that the user produces right value in captcha..
View 22 Replies
Mar 26, 2016
I want to display the value in table which i calcute in chart. Ex:
month salary
march(chart xaxis) 2000(chart yaxis sumof salary)
april 3000
View 1 Replies
Feb 28, 2011
First off, I am wondering if this is possible. I read slight grumblings around the internet about this, but I was not entirely sure.
My scenario: I have a base chart class which has some methods which all charts should have.
public partial class BaseChart : System.Web.UI.UserControl
{
public BaseChart()
{
}
public void ToggleLegend()
{
Chart1.Legends[0].Enabled = !Chart1.Legends[0].Enabled;
}
}
There is also some mark-up for this BaseChart -- setting background colors, etc. All charts which inherit BaseChart should use this starting mark-up and be able to build upon it.
I would then like to do this:
public partial class HistoricalLineChart : BaseChart
{
public HistoricalLineChart()
: base()
{
public HistoricalLineChart(int reportID)
: base()
{
Chart1.Titles[0].Text = "Hello World";
}
}
where HistoricalLineChart is a web user control with no mark-up e.g. "HistoricalLineChart.ascx"
The problem is that Chart1 is undefined when in HistoricalLineChart's scope. Is there something that I am missing here?
View 3 Replies
Feb 3, 2011
LoginPage.aspx:-
protected void Button1_Click(object sender, EventArgs e)
{
Context.Items["Username"] = txtUserId.Text;
Context.Items["Password"] = txtPassword.Text;
//
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Context.Items["Username"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(10), true, "users", FormsAuthentication.FormsCookiePath);
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
Response.Redirect("Default.aspx");
}
Global.asax file:-
void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
// Get the stored user-data, in this case, our roles
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
Response.Write(HttpContext.Current.User.Identity.Name);
Response.Redirect("Default.aspx");
}
}
}
}
I get the following error after signing in This webpage has a redirect loop.
The webpage at [URL] has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
View 2 Replies
Sep 16, 2010
How can I produce a CSV file. My loop shown below works just fine.. I just don't know CSV part.
foreach (Employee data in e)
{
Console.WriteLine("{0}{1}",data.EmployeeId, data.FirstName);
}
View 3 Replies
May 31, 2010
I want to output some dynamic data from an ASP.NET website to Excel. I found that the easiest way which does not require to use Excel XML or to install Excel on server machine is to output data as a table and specify application/vnd.ms-excel type
View 3 Replies
Mar 3, 2010
All ASP.Net client validation messages can be shown as an alert by setting the ShowMessageBox="True" property on the ValidationSummary control. This works fine for anything that happens on the client.
For the custom validators that validate server-side I had assumed that what would happen is that when the page is returned to the browser, ASP.Net would inject some javascript to show the alert box. However this isnt the case.
If you had relied on the message box to show detail and just have a * next to the erroneous field (as per my clients req's) then it wont work as intended. Does anyone have a solution for doing this? What I want is a way to possibly override the ValidationSummary control to inject javascript onto the page or something like this.
View 1 Replies
Mar 21, 2010
I've written a ASP.NET app that I hope to sell to businesses, I could host the trial but it's designed to connect to the customers data so customers will certainly want to install it to do a successful evaluation.
I've never produced anything commercial before so I'm looking for advice on how best to limit the trial, a 30 day trial seems most common, do you simply rely on the clock of the PC/Server they install it on? keep in mind this is ASP.NET app so will be installed on their web server.
View 4 Replies
Nov 30, 2010
I'm trying to do just as the title of this thread says:
I have a dropdownlist and to pick a client, and if there is no assignments (a different table) with that client in it I want the page to produce an error messagebox instead of going to the postbackURL.What would be the easiest way to do this?
View 1 Replies
Feb 2, 2010
I've seen various controls in ASP.NET with "collections" of objects, which you can use markup to define. For example:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp
/Triggers>
</asp:UpdatePanel>
In the above example, you can add any number of triggers, and they can be of any type that extends UpdatePanelTrigger. I'd like to do something similar, but with only a single item instead of a collection
View 2 Replies
Feb 22, 2010
I've subclassed the RequiredAttribute with am implementation that leverages existing localization resources. When I use my subclassed attribute, the client side validation code generated MVC when Html.EnableClientValidation() is invoked doesn't work as it fails to recognise the parent RequiredAttribute type.
I've tried to override the GetType() method to try and cloak my subclass and this didn't work. I've also had a look at some of the solutions out there for implementing a localizable RequiredAttribute where some solutions require you to subclass it or implement a provider which I already have. For the purpose of my implementation, another layer of localization is not an option.
Here is my implementation of the RequiredAttribute subclass leveraging a localization provider:
[Code]....
When I attribute a model property with the above, client side validation is broken, however, with the original RequiredAttribute class, client side validation works as expected. Does anyone have a workaround to solve this issue or would it be suitable to recommend that the code that generates the client side validation scans the inheritance hierarchy for a RequiredAttribute type and morph my subclass into the base class.
View 3 Replies
Jan 19, 2010
If I'm writing in-line code on a .aspx page is it possible to override the onLoad of the class that the .aspx is directly inheriting from? Right now if I do the override the base.onLoad inline on the .aspx page it is overriding the "Page" object's onLoad event not the class the .aspx is inheriting from.
View 1 Replies
May 9, 2010
If a user enters a non-numeric value into a TextBox and presses a Button, I want to show an error message on a Label. How can I achieve this?
View 3 Replies
Jul 29, 2010
I have a C# project in Visual Studio that produces an aspx page. The code I am editing is in default.asp.cs. When I build the project a file default.aspx is produced. This file looks something like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CSRValidationConnector._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" [URL]-transitional.dtd">
<html xmlns="[URL] >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
When I make my web request most of this page comes back. But I want the page to return only plain text and not any of this HTML. How do I configure things so that nothing is returned except what I add via Response.Write calls in default.aspx.cs?
View 2 Replies
Feb 7, 2011
I a trying to produce embedded 'if' conditions in Stored Procedure.
I have the SP working without the embedded IF stmts indicated below.
I would like to have an easier method to choose the SQL stmt based on the user selection for the operand <>=.
[Code]....
the embedded IF stmts are the onese I am having issues with....
[Code]....
View 7 Replies