C# - Difference When Declaring A DataSource In Markup Compared To Code Behind
Jan 13, 2011
I have a legacy solution where all the DataSources are defined in the markup for all .aspx-pages. The problem I have with this is that the DataSource get instantiated several times since it is used in page, control... What I want is to have NInject to handle the instantiation of the DataSource so this doesn't happen. I have got that part to sort of work, but when the DataSource is defined in the code-behind instead of in the markup the Page property is not set on the DataSource, does anyone know why? A simple solution to this is to set the the Page property in a base class or something, but I do think that the property should be there and want to know why.
I got a simple SQL Connection which works fine under VS 2005, once I convert to VS 2008, is failed to work. I even re-build entire apps from scratch under VS 2008, yet it still failed.
Here's the code.
[Code]....
The code failed at this line:
objCon = New SqlConnection()
Error message being:
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Is it possible to do things in a PHPish way in ASP.Net? I've seen <%= %> but I've tried it and couldn't get it to work. The PHPish equivalent of what I want to do is
I've been working on the ASP.NET Development Server recently (on an MVC project and I'm finding that it is inconsistent in how it serves the changes I make to my code. For example, I make a change to the C#/HTML/CSS/JS in the dev environment and run the page, and the change appears on the screen. But if I edit the HTML again and run the page again, the new change doesn't appear. Even ctrl+F5 doesn't do it. I have to stop the web server and run the app again for the changes to update. Has anyone else experienced this? Is there a way to sort this problem out?
If I'm working in IIS and I change something, a ctrl+F5 will always update the page with the changes I've made. I'd like the dev server to be as reliable.
While it has gnerally been advocated to separate code from mark up and all that, with the razor syntax and webmatrix all that is not valid anymore, I think. WebMatrix encourages code and mark up in the same page! So what is the best practice as far as code and mark up is concerned.
I'm trying to add some basic HTML markup to my code-behind, just a H1 and a few breaks separating strings in the message.Body, but can't seem to get it going without errors.
[Code]....
Probably a straightforward thing, or not intended usage at all,
I'm new to custom server controls and I'm hoping to use them to build various 'modules' for different sites I build to cut down on duplicate code.I'm familiar with custom user controls in which I can create an .ascx & .ascx.vb file which can then be imported into an .aspx page and used freely.However, with custom server controls I cannot find a way of using markup/html code. Is this possible at all or must all code be created programmatically?
I have a public property defined in code behind of a user control. I want to toggle visibility of controls in the markup based on the property's value.
using gridview delete button with datasource markup: source Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:direct_deliveryConnectionString %>" SelectCommand="select pk_ddlvryDetailID,fk_grfdetailID,itemDescription,qty,uom,rate,(qty*rate) as Amount from qddlvrydetails where fk_ddlvryMasterID=@id" DeleteCommand="delete from tblddlvrydetails where pk_ddlvrydetailid=@id"> [code]... I created a parameter named @ID which will received value from grid selectedvalue whenever the delete button fire up but whenever i do that the will just postback without delete the row.
I've got a Linq datasource hitched up to a Formview control for clients to edit some data. I'm having trouble setting the where parameters withing the control so it show the right set of data. Here's the markup:
[Code]....
Upon running right now, it's completely ignoring the where parameters. What am I missing here?
I'm building form validation controls for our C# ASP application. The bulk of the work is handled by a BaseValidator control (subclassing System.Web.UI.UserControl), which also has the markup for the validation output. This is then extended by subcontrols like PasswordValidator, that provides the Validate method and any extra fields needed by that validator control.
(The end goal is to have controls like <uc1:PasswordValidator ControlId="txtPassword" /> which we can plop into any form with minimum duplication.)
However, PasswordValidator.ascx.cs cannot access the form elements defined in BaseValidator.ascx; the only way I've found to do so is to duplicate the markup in each subcontrol's *.ascx file. How can I extend BaseValidator.ascx.cs and access BaseValidator.ascx's markup in the subclass?
When I first created a timer (Timer1) I handled the Tick event. No problem, intellisense worked and the timer control was declared then. I toggled it's enabled property, no problem.
I just went to look back at the _Tick event for the Timer1 control, and it has the blue underline mark in VWD that says that Timer1 is undeclared. I looked back at the markup and the <asp:Timer ID="Timer1" runat="server" ... /> control is there. I don't understand why all of a sudden my code-behind class is not recognizing the ID of my timer control.
The page runs fine, but it is throwing me off why VWD is seeing this as an error when I hard-type the control name.
I've been thinking about starting to work with AJAX because it seems easy to use things like the update panel. I also want to use a modal popup. I know that JQuery has some really stuff and I want to use it eventually. I want to take the path of least resistance for now though.
there seems to be some overlap in what the two technologies offer. There are similar things offered in both of them. I think I have to use AJAX for the partial page updates though.
How is the learning curve for JQuery compared to AJAX?
How can I tell the difference between source and published .NET code?
I am looking at some inherited code that I have not touched in about a year. The original designer had me first publish locally before uploading the published code to the internet server. Now I am looking a number of backed up source folders as well bas backed up published folders. I should have done a better job at naming the folders, I guess. Now I wonder: How can I tell the difference between source and published .NET code? Is there some easy way to see if some folder that contains only published code is lacking a file or xml setting?
Is the .csproj file or the .sln file part of the code pushed to the server when you publish? What other differences are there that I are immediate and obvious?
I have developed an application that interacts with IBM ClearQuest. The problem is that when I run everything locally, such as, run the webservice local and then ASP page local everything is at the speed I expect. When I post the webservice (precompiled) to the server and run the web page through the server, the call to the webmethod takes at least 10x the amount of time it should. I dont know why this is happening. I made a console application that has the function in question and execute it on the server and locally and they both return the same amounts of time (roughly) its just when I move to executing via the webmethod everything grinds to a snails pace. Any ideas? This happens every time not just on the first call.
WebMethod:
Public Function RetrieveQueryResults(ByRef cqSession As ClearQuestOleServer.Session, _ ByVal sqlStmt As String) As List(Of SearchResultsSingleIssue) Dim numCols As Integer, status As Integer, columnIdx As Integer Dim numRows As Integer Dim rowContents As String = "" Dim colValue As New Object Dim colLabel As New Object Dim allitems As New List(Of SearchResultsSingleIssue) Dim results As New SearchResultsSingleIssue Dim cqResultSet As ClearQuestOleServer.OAdResultset cqResultSet = cqSession.BuildSQLQuery(sqlStmt) cqResultSet.Execute() ' Get the number of columns returned by the query. numRows = 0 numCols = cqResultSet.GetNumberOfColumns status = cqResultSet.MoveNext ' Collect query results. Do While status = AD_SUCCESS results = New SearchResultsSingleIssue numRows = numRows + 1 For columnIdx = 1 To numCols colLabel = cqResultSet.GetColumnLabel(columnIdx) colValue = cqResultSet.GetColumnValue(columnIdx) 'Make sure that we dont pass along a null reference If colValue = Nothing Then colValue = "" End If Select Case colLabel Case "ID" results.IssueID = colValue Case "HEADLINE" results.Headline = colValue Case "NAME" results.State = colValue Case "OE_CONTACT" results.OEContact = colValue Case "DESCRIPTION" results.Further_Description = colValue Case "PRODUCT_NAME" results.Product_Name = colValue Case "FUNCTIONAL_AREA" results.Functional_Area = colValue Case "SUBTOPIC" results.Subtopic = colValue Case "FOUND_VERSION" results.Found_In = colValue Case "SCHEDULED_VERSION" results.Scheduled_For = colValue Case "SYMPTOMS" results.Symptoms = colValue Case "AFFECTED_SYSTEMS" results.Affected_System_Types = colValue Case "ISSUE_TYPE" results.Issue_Type = colValue Case "ASSIGNED_TO" results.Assigned_Developer = colValue Case "TESTED_BY" results.Assigned_Tester = colValue Case "BUILT_VERSION" results.Built_In = colValue Case "TESTED_VERSION" results.Tested_In = colValue Case "NOTES_LOG" results.Notes_Log = colValue Case "CUSTOMER_SEVERITY" results.Severity = colValue Case "PRIORITY" results.Priority = colValue End Select Next columnIdx ' Add the query row result to the compiled list of all rows. allitems.Add(results) status = cqResultSet.MoveNext Loop Return allitems End Function
We have a .aspx file which has about 400 lines of javascript code. Is it a good idea to have such huge code in its own file? What is the performance difference in having huge javascript code in aspx as against the .js file?