Hi all,
I've got a conditional compilation symbol I'm using called "RELEASE", that I indicated in my project's properties in Visual Studio. I want some particular CSS to be applied to elements when the RELEASE symbol is defined, and I was trying to do that from the view, but it doesn't seem to be working.
My view code looks like this (shortened a bit for demo purposes):
<% #if (RELEASE) %>
<div class="releaseBanner">Banner text here</div>
<% #else %>
<div class="debugBanner">Banner text here</div>
<% #endif %>
With this code, and with the RELEASE symbol set, the 'else' code is running and I'm getting a div with the debugBanner class. So it doesn't seem to think that RELEASE is defined. It's worth noting that my actual C# code in .cs files is recognizing RELEASE and runs the correct code. It's only the view that is giving me the problem.
Does anyone have any insight into this? Any help would be appreciated. Thanks.
How to set up auto mapping to map System.Collections.Generics.ISet<T> correctly?
I tried implementing IHasManyConvention, but in intellisense it seems that IOneToManyCollectionInstance does not have anything for that(?)
Hi
I have the following code sample, where the only difference between the 2 parts of the If statement is the less than/greater than operators.
Is there a better way to write this? Could almost do with being able to define an Operator variable.
If myVar = true Then
Do While (X < Y)
'call Method A
Loop
Else
Do While (X > Y)
'call Method A
Loop
End If
thanks
I have a C# function that does some processing and needs to return figures about what it has processed, success, failure, etc.
Can anyone tell me if there are any standard framework classes that will handle this (for example, number of records processed, number successful, failed, etc) ?
Alternatively, can anyone say how they usually handle this? Is the best way to create a class, or to use out parameters?
I've been using my own Error reporting module which was combination of simple c# and jQueryUI Dialog. Problem is that once error or success occurs i do write it's value to session. It does work pretty good on pages with Responce.Redirect on error but not on pages where i catch an error and then return to same form.
My question is why does session which added pre-postback fails to load in pages where i have return statement on some condition.
And if there another way to save errors and success message except in session ? Maybe global variables or something like that ...
Hi guys, i have a problem with cross-domain cookies. I read a lot of documentation about sharing cookies between subdomains. The main idea of all articles is set Domain property to something like ".mydomain.com". I've created two domains on local IIS server - test1.local.boo and test2.local.boo. They works great and visible with browser. I have the following code:
Site test1 - Writes cookie:
HttpCookie myCookie = new HttpCookie("TestCookie");
myCookie.Domain = ".local.boo";
myCookie["msg"] = "Welcome from Cookie";
Response.Cookies.Add(myCookie);
Site test2 - Reads cookie:
HttpCookie cookie = Request.Cookies["TestCookie"];
if (cookie != null)
{
Response.Write(cookie["msg"]);
}
else
{
Response.Write("FAILED");
}
This code always shows FAILED message. So it means that second site can't read cookie from the same subdomain. Where is my mistake??
I've gotten myself stuck on how to handle inheritance in my model when it comes to my controllers/views.
Basic Model:
public class Procedure : Entity
{
public Procedure() { }
public int Id { get; set; }
public DateTime ProcedureDate { get; set; }
public ProcedureType Type { get; set; }
}
public ProcedureA : Procedure
{
public double VariableA { get; set; }
public int VariableB { get; set; }
public int Total { get; set; }
}
public ProcedureB : Procedure
{
public int Score { get; set; }
}
etc... many of different procedures eventually.
So, I do things like list all the procedures:
public class ProcedureController : Controller
{
public virtual ActionResult List()
{
IEnumerable<Procedure> procedures = _repository.GetAll();
return View(procedures);
}
}
but now I'm kinda stuck. Basically, from the list page, I need to link to pages where the specific subclass details can be viewed/edited and I'm not sure what the best strategy is.
I thought I could add an action on the ProcedureController that would conjure up the right subclass by dynamically figuring out what repository to use and loading the subclass to pass to the view. I had to store the class in the ProcedureType object. I had to create/implement a non-generic IRepository since I can't dynamically cast to a generic one.
public virtual ActionResult Details(int procedureID)
{
Procedure procedure = _repository.GetById(procedureID, false);
string className = procedure.Type.Class;
Type type = Type.GetType(className, true);
Type repositoryType = typeof (IRepository<>).MakeGenericType(type);
var repository = (IRepository)DependencyRegistrar.Resolve(repositoryType);
Entity procedure = repository.GetById(procedureID, false);
return View(procedure);
}
I haven't even started sorting out how the view is going to determine which partial to load to display the subclass details.
I'm wondering if this is a good approach? This makes determining the URL easy. It makes reusing the Procedure display code easy.
Another approach is specific controllers for each subclass. It simplifies the controller code, but also means many simple controllers for the many procedure subclasses. Can work out the shared Procedure details with a partial view. How to get to construct the URL to get to the controller/action in the first place?
Time to not think about it. Hopefully someone can show me the light. Thanks in advance.
I've seen developers use two approaches when they are done with a session object.
1) Session.Remove(key)
2) Session(key) = nothing
What is the better approach of the two above? Does Session.Remove dispose the object stored automatically?
Does the second approach depend on the garbage collector to actually free up the memory?
Thanks.
Assume I have method
void SomeMethod(Action callback)
This method does some work in background thread and then invokes callback. The question is - how to block current thread until callback is called ?
There is an example
bool finished = false;
SomeMethod(delegate{
finished = true;
});
while(!finished)
Thread.Sleep();
But I'm sure there should be better way
I need to download a LARGE file (2GB) over HTTP in a C# console app. Problem is, after about 1.2GB, the app runs out of memory.
Here's the code I'm using:
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(username, password);
byte[] fileData = request.DownloadData(baseURL + fName);
As you can see... I'm reading the file directly into memory. I'm pretty sure I could solve this if I were to read the data back from HTTP in chunks and write it to a file on disk.
Does anyone know how I could do this?
In my aspx page I have drop down list that initialy in page load event loads up with list of values which is shown to client(drop down list "A") and in client side, depending on client selecion of another drop down list(drop down list "B") I have written a javascript to update drop down list "A" with corresponding values with Ajax behaviour(without full page postback).
But when we post page to the server, in server side page load event shows initialy sent list of values for drop down list "A" but not the values that were loaded by Ajax calls due to ViewState not being updated correctly due to Ajax call. I could fix this easily with update panel but it increased Ajax request size to 44KB which is much higher than what currently is for hand made Ajax script I have written( 0.5KB) Is there special way of fixing this rather than using update panel?
I have a very big table with a lot of rows, every row has stats for every user for certain days. And obviously I don't have any stats for future. So to update the stats I use
UPDATE Stats SET Visits=@val WHERE ... a lot of conditions ... AND Date=@Today
But what if the row doesn't exist? I'd have to use
INSERT INTO Stats (...) VALUES (Visits=@val, ..., Date=@Today)
How can I check if the row exists or not? Is there any way different from doing the COUNT(*)?
If I fill the table with empty cells, it'd take hundreds of thousands of rows taking megabytes and storing no data.
I'm trying to bring a C++ library into C#, so naturally I am trying to make a C++/CLI project.
In visual studio I created a new project (Visual C++ project, class library). I then tried to make a test class out of the pre-generated "Class1"
namespace Test {
public ref class TestIt
{
public:
void DoWork()
{
System::Console::WriteLine("sup");
}
// TODO: Add your methods for this class here.
};
}
So I compile in and go to the build folder.... hrmm no .dll wetf?? There's a .dll.intermediate.manifest file, but no .dll.
So wut I did wrong?
Hi,
I need to run a javascript function when the update panel is loaded completely(I want to scroll), and not on initial page load.
Please suggest.
Thanks
In my web.config file i have the following code:
<system.web>
<assemblies>
<authentication mode="Forms">
<forms loginUrl="/Account/Login" slidingExpiration="true" timeout="1" />
</authentication>
<sessionState timeout="1"></sessionState>
</assemblies>
</system.web>
And I have main page Project and in that there will sub pages. I have given the [Authorize] attribute for each view index method.
After the session complete when we select any view then the page inside the project main page will be redirecting. But I want the whole page to be redirected.
Any Help is appreciated.
I have implemented ajax on paging but my problem is when i navigate on paging and go to page 1 then on page 2 after that if i press backspace it went to the last page from where it comes instead of going to page 1. I want to know how should i implement paging like stackoverflow have. Further i have noticed that my url doesnt change on paging it remains like Home/Index when im on 1st page or 2nd page or any other page?
Hey,
I'm developing a web application that provide a service of online reservation, and I need to save the data (for example in a specific day and access to them).
How can I do that.
Is it possible using : System.Web.UI.WebControls.Calendar
I have a list box which is populated using a dictioanry. When I iterate throught the selected items using the following code, it always show only the first items as selected - even if the first item is not selected.
Have you ever encountered this scenario?
Could you please help on this?
foreach (ListItem item in lstProcessName.Items)
{
if (item.Selected == true)
{
selectedNewSales.Add(item.Text);
}
}
Hi all
I know that the EURO currency symbol (€) is encoded as € in HTML, but the System.Web.HttpUtility.HtmlEncode("€") doesnt encode it at all. Does anyone know why that is?
Thanks
I am packing bytes into a struct, and some of them correspond to a Unicode string. The following works fine for an ASCII string:
[StructLayout(LayoutKind.Sequential)]
private struct PacketBytes
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string MyString;
}
I assumed that I could do
[StructLayout(LayoutKind.Sequential)]
private struct PacketBytes
{
[MarshalAs(UnmanagedType.LPWStr, SizeConst = 32)]
public string MyString;
}
to make it Unicode, but that didn't work. (Since this field is part of a struct with other fields, which I've omitted for clarity, I can't simply change the CharSet of the containing struct.)
Any idea what I'm doing wrong?
the thing is that I have a form with a textbox and a button and a hidden field, now what i want to do is to write something in the textbox ,pass it to the hidden field and then access that thing written in the hidden field in the controller . how can i do that?
Is there a simple way of making the static content of an .aspx page multi-lingual? Resource files are nice for controls but it's quite hard and annoying to write big chunks of html in them. Any easier ways?
Hi I have the following codes
$('#<%= btnOpen.ClientID %>').click(function() {
$('#content').modal();
});
<asp:Button ID="btnOpen" runat="server" Text="Open" />
When I click on the button, the modal window will appear for about 0.5 second and disappear right away.Can anyone help me please? Thanks a lot!