|
First thing you should check is the whether formview is getting databound on each postback or only one first postback . because if it is getting databound on each postback then you will have to make it do that only on first load and not on each postback .
If that doesn't work then, My suggestion is that you handle the ItemDataBound event too. get the value in this event and save it somewhere (like session variable). then in this event get the new value and compare it with the one in in session variable.
Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.
|
|
|
|
|
When comparing text, you have to do a compare against the actual values of the text, and not the string representations held in e.NewValues and e.OldValues. That type of comparision is good for numbers, or short text such as "GOOD" or "BAD"
So text is really stored as a byte array like 37 80 68 70 45 49
Doing a String.Compare will examine the byte array of the strings, and give you an accurate result.
In your case, I don't what the values are, but NewValue != OldValue will not produce a consistent result.
If String.Compare(path, 0, "file:", 0, 5, True) = 0 Then
Return True
Else
Return False
End If
classy_dog wrote: However the problem is the values are actually the same. By stepping through the code, the application thinks the values are different.
You lost me here. You know the values are a match, but stepping through the code shows you different values.
I going to go with an inaccurate result being produced by your comparison
|
|
|
|
|
classy_dog wrote: By stepping through the code, the application thinks the values are different.
That's because you are comparing the values of the objects and not their content. You need to do a String.Compare() [^] to compare the string data; the == and != operators will merely tell you whether the two references point to the same or different objects.
[edit]
Well I was wrong as, according to MSDN[^] strings are a special case. I can only conclude that the dictionary is not returning string s in the sample you showed.
[/edit]
|
|
|
|
|
I knew you had to do a string.compare, and some of the details of it, but didn't think of his code as comparing objects, and not the actual value.
Nice Answer!, I even learned from it.
|
|
|
|
|
According to this[^] it looks like I was wrong. Time for a big slice of crow pie, followed by some C# testing.
[edit]
I suspect the dictionary that OP is using, does not return pure strings in the sample shown.
[/edit]
|
|
|
|
|
We got a little debate going on here in this rodeo cowboy
I read the reference you pointed to, and I must support your first argument regarding comparison operators and objects
Operator B for string b = string.Copy(a) returns false, but a and c returns true
string a = "hello";
string b = String.Copy(a);
string c = "hello";
Console.WriteLine(a == b);
Console.WriteLine((object)a == (object)b);
Console.WriteLine((object)a == (object)c);
Anwsers:
True
False
True
[edit]
The op took a shortcut by using an operator against the objects, and failed to create 2 new buffers to store the actual values he needs to string compare.
I threw a little c++ lingo in there.
|
|
|
|
|
Casting the string s to object s means that the == operator will compare their addresses to see if they point to the same object (same as comparing two pointers in C++). As I said, I suspect that the dictionary indexing operations do not return 'pure' strings.
|
|
|
|
|
Oh! OK, I understand now. pure strings
|
|
|
|
|
|
I forgot to mention,
After working in c++ using the strcmp macro, and walking through it a hundred times, I get a pretty good idea of how it works, how the strings are actually compared down to the byte value for an exact match.
But in the case of asp.net whether it's vb or c#, I assume the string.compare uses a similar method of comparison down low underneath. I suppose one could write something similar using bytes in vb or c#.
I've never been able to walk through an operator, to see what it really does.
But I think your right about the OP just compared object pointers, and got a match.
|
|
|
|
|
Hi,
Have you ever been in a situation where you needed a scheduled task to kick off, but you didn’t have access to the server (think shared hosting)? I originally saw this hack on Samir’s blog about a year ago now.
Essentially, you just create a System.Timers.Timer in the Application_Start event of your global.asax, and bam – instant scheduled task! I don’t necessarily recommend this, but I guess if you had no other option it could work.
using System.Timers;
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Timer timer = new Timer(1000);
timer.Elapsed += (object s, ElapsedEventArgs args) =>
{
LetsDoSomethingAwesome();
};
timer.Start();
}
}
Thanks & Regards
--AK
|
|
|
|
|
You have been a member here long enough to know that these forums are not for this type of message. Please follow the site protocol.
|
|
|
|
|
Plagarized from http://codeharder.com/?tag=/hacks[^].
If you are going to copy/paste someone else's work, you must provide credit to the original source.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I have a question about using session variables since this is the first C# 2010 web form app that I am running.
Right now I am passing 3 session variables between 2 web pages in the web application that I setup. This is a data entry application where some information is entered on page 1 and the rest of the information is entered on page 2.
When the user has finished entering the information for the first customer. Now the user will be ready to setup information for the second user.
From what I have seen on the internet session variables last up to 20 minutes. Thus I basically do not want the information saved from customer 1 to be entered into the database file for customer 2 by using session variables.
Thus to prevent this from occuring, I am coding the following before the user clicks the button to enter data for the next customer:
Session.Remove("var1");
Session.Remove("var2");
Session.Remove("var3");
Response.Redirect("~/page1.aspx");
Can you tell me if this is the best method for clearing out session variables and/or if there is a better process you would recommend? Can you tell me and/or point me to a reference that will explain your answer to me?
|
|
|
|
|
try to use session timeout.Sometime,network is not well and session has not remove.
|
|
|
|
|
Looking into the above description, i could make 2 things.
1. you have some session variables that you are using for custom logic.
now you want to use session["var1"] for filling customer1 information.
2. you might have some session variables that are required for maintaining user sessions. (probably)
and perhaps with the same user ID you will have to use the same session variables with separate set of data.
Session.Remove("var1"); for all the variables should work once you save the data into database. but in case you dont have the requirement mentioned in #2 point i.e. maintaining user session then instead of clearing the variables one by one you can simply do a session.Abandon too.
in short, if you are not using sessions to track the login status then you can use session.abandon too.
Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.
|
|
|
|
|
I would check to see if the session exist first before removal, so you don't generate a object does not exist error.
[EDIT] wrap code in tags
If Not Sesson("var1") Is Nothing Then
Session.Remove("var1")
End If
|
|
|
|
|
|
I am asking this question since this is the first C#.net 2010 web form application that I am writing. In this application I am using linq to sql to connect to a sql server 2008 r2 database since that is what the rest of the web pages do in this application.
My question is on one particular web form page, I have been creating new datacontexts objects for each button that is used on this web form page. All these data context objects refer to the same .dbml file.
Thus I am wondering if I should use only one data context object and put that creation of the data context object on top of the web page and give it a protected web form page access?
Can you tell me and/or point me to a reference that will tell me what the best way is to handle this situation and show me how to accomplish this task in code?
|
|
|
|
|
sc steinhayse wrote: if I should use only one data context object and put that creation of the data context object on top of the web page and give it a protected web form page access
I would suggest one datacontext but this way: Request scoped DataContext [^]
Also, read about datacontext to understand it's role and what it does, here: MSDN: LINQ to SQL - Datacontext[^]
|
|
|
|
|
In a C# 2010 webform application I am working on a couple of custom validators. One of the validators needs to look at a sql server 2008 r2 database to find the lowest and highest value for a create date field.
My question is how to setup a customer error message that can be generated. Basically I would like the error message to say the create date needs to be within a certain date range. I would do not want to say the create date requested values is not contained in the specific table.
Thus can you tell me how to setup a custom error message that the custom validator can use?
|
|
|
|
|
|
That uses the same concept as if checking to see if a username exist before form submission.
Most people write JavaScript, to capture the value, and submit it to a web service, the web service then sends back the answer, or parameters needed to make a decision, and then the same JavaScript does a comparison, and creates a validation message, or alters the GUI for a clean notification.
concept sample
This is a link on the CJ that clarifies my thoughts into code, with explanations.
|
|
|
|
|
Hi,
We have developed an application using ASP.net 2008 and SQL server 2008. when it runs locally, it works okay but when it is published to a host. It creates following error:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load file or assembly 'Telerik.Web.UI, Version=2010.2.929.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 1: <%@ page title="" language="C#" masterpagefile="~/MasterPages/ProductsCatalog.master" autoeventwireup="true" inherits="ProductsCatalog_Subcategories, App_Web_subcategories.aspx.915388b4" enableviewstatemac="false" theme="Austin4" viewStateEncryptionMode="Never" maintainScrollPositionOnPostBack="true" %>
Line 2: <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
Line 3: <asp:Content ID="Content1" runat="server" ViewStateMode="Disabled" ContentPlaceHolderID="ContentPlaceHolder2">
Source File: /ProductsCatalog/Subcategories.aspx Line: 1
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Telerik.Web.UI, Version=2010.2.929.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Any comment or suggestion for resolving this error is appreciated.
|
|
|
|
|
Could not load file or assembly 'Telerik.Web.UI, Version=2010.2.929.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies.
You are using Telerik controls in your application. You must have installed Telerik controls on your system such that you can use them in your project locally. Post installation, you have telerik dll's reference in your project that allowed you to use the telerik controls.
When you published it on server, application is looking for telerik assembly (Telerik.Web.UI, Version=2010.2.929.40) to reference the controls used but is missing. Just find the telerik dll on your local system and place it in BIN folder of your web application on server. It should be good to go.
|
|
|
|