I've created links in the listview which is attached to the datapager. When a user clicks a link they see content to the left but the datapager changes from any page to page 1.
I have an Action Method that I'd either like to return JSON from on one condition or redirect on another condition. I thought that I could do this by returning ActionResult from my method but doing this causes the error "not all code paths return a value"
Can anyone tell me what I'm doing wrong? Or how to achieve the desired result?
Here's the code below:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Login(User user)
{
var myErrors = new Dictionary<string, string>();
try
{
if (ModelState.IsValid)
{
if (userRepository.ValidUser(user))
{
RedirectToAction("Index", "Group");
//return Json("Valid");
}
else
{
return Json("Invalid");
}
}
else
{
foreach (KeyValuePair<string, ModelState> keyValuePair in ViewData.ModelState)
{
if (keyValuePair.Value.Errors.Count > 0)
{
List<string> errors = new List<string>();
myErrors.Add(keyValuePair.Key, keyValuePair.Value.Errors[0].ErrorMessage);
}
}
return Json(myErrors);
}
}
catch (Exception)
{
return Json("Invalid");
}
}
Hi, im using asp:menu for showing the menus in masterpage. If i click the menu item 1, the corresponding page is loading in the content page. I need that the selected Menu item should be highlighted by some color.pls Help me out
Menu coding is follows:
<items>
<asp:menuitem text="Home" Value="Home" NavigateUrl="~/page1.aspx"></asp:menuitem>
<asp:MenuItem NavigateUrl="~/page2.aspx" Text="About" value="About"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/page1.aspx" Text="Contact" Value="Contact"></asp:MenuItem>
</items>
<StaticSelectedStyle BackColor="#1C5E55" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#666666" ForeColor="White" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#666666" ForeColor="White" />
<StaticItemTemplate>
<%# Eval("Text") %>
</StaticItemTemplate>
</asp:menu>
I have used the Entity Framework with VS2010 to create a simple person class with properties, firstName, lastName, and email. If I want to attach DataAnnotations like as is done in this blog post I have a small problem because my person class is dynamically generated. I could edit the dynamically generated code directly but any time I have to update my model all my validation code would get wiped out.
First instinct was to create a partial class and try to attach annotations but it complains that I'm trying to redefine the property. I'm not sure if you can make property declarations in C# like function declarations in C++. If you could that might be the answer. Here's a snippet of what I tried:
namespace PersonWeb.Models
{
public partial class Person
{
[RegularExpression(@"(\w|\.)+@(\w|\.)+", ErrorMessage = "Email is invalid")]
public string Email { get; set; }
/* ERROR: The type 'Person' already contains a definition for 'Email' */
}
}
I have a class called
MyClass
This class inherits IEquatable and implements equals the way I need it to. (Meaning: when I compare two MyClass tyupe objects individually in code, it works)
I then create two List:
var ListA = new List<MyClass>();
var ListB = new List<MyClass>();
// Add distinct objects that are equal to one another to
// ListA and ListB in such a way that they are not added in the same order.
When I go to compare ListA and ListB, should I get true?
ListA.Equals(ListB)==true; //???
I have a Categories table in which each category has a ParentId that can refer to any other category's CategoryId that I want to display as multi-level HTML list, like so:
<ul class="tree">
<li>Parent Category
<ul>
<li>1st Child Category
<!-- more sub-categories -->
</li>
<li>2nd Child Category
<!-- more sub-categories -->
</li>
</ul>
</li>
</ul>
Presently I am recursively rendering a partial view and passing down the next category. It works great, but it's wrong because I'm executing queries in a view.
How can I render the list into a tree object and cache it for quick display every time I need a list of all hierarchical categories?
I write vbs that create ole atomation object
On Error Resume Next
dim objShell
dim objFolder
if not objFolder is nothing then
objFolder.CopyHere "ftp://anonymous:[email protected]/bussys"
WScript.Sleep 100
end if
set objShell = nothing
set objFolder = nothing
How to do that on C# (or do that without ole automation just use com) ? Or do that on c++ without MFC.
Hi,
I used a javascript FocusChange() in my aspx page. I have couple of controls and I need Hit enter key need to move next control based on tab index. It is working good in IE7 but not working in IE8... Please help me on this..
Thanks for your help in advance. The java script is given below.
function FocusChange() {
if (window.event.keyCode == 13) {
var formLength = document.form1.length; // Get number of elements in the form
var src = window.event.srcElement; // Gets the field having focus
var currentTabIndex = src.getAttribute('tabindex'); // Gets its tabindex
// scroll through all form elements and set focus in field having next tabindex
for (var i = 0; i < formLength; i++) {
if (document.form1.elements[i].getAttribute('tabindex') == currentTabIndex + 1) {
for (var j = i; j <= formLength; j++) {
if (document.form1.elements[j].disabled == false) {
document.form1.elements[j].focus();
event.returnValue = false;
event.cancel = true;
return;
}
}
}
}
}
}
Hello,
I have 2 question about sqlmetal.exe
I generate Linq to Sql classes from command promt for all tables, except some tables?
can I add to model some tables
I want that, in some cases linq to sql classes not generated fully.
thanks.
Hey,
I currently have a system on my website whereby I can put something like "[cfe]" anywhere in the site and, when the page is rendered, it will replace it with the root to the customer front end (same for "[afe]" and admin front end - so in the admin front end I can put "[cfe]/Default.aspx" to link to the homepage on the customer front end. This is in place as I have a development version of the site, then a test and a live version too. All 3 may have different roots to each section (for example the way the website is set up, the root to the admin front end in test is "/test/Administration/", but in live and development it is just "/Administration/"). Which version it is depends on the URL - all my development sites are in a folder called "development", whereas test is in a folder called "test" and any live urls do not contain either of these. There are also 3 different databases - one for each. All 3, obviously, require a different connection string.
I also have a string replacement function in place which can change, for example, "[Product:Cards]" to point to the Cards catalogue page. Problem is that for this I go through all the products and do a replacement on "[Product:" & Product.Name() & "]".
However I would like to take this further. I would like to pick up these custom strings when the page is rendered so it picks up "[Product:Cards]" and then goes off to find product "Cards" and replaces the string with a link to the Cards page, rather than looping through all the products and doing a replace just on the off chance that there are any replacements to make.
One use for this, which I may start using in the future if I can figure out how to do this, is like on Wikipedia where you put the title of the page you want to point to, then a divider (think its a pipe from memory) then the link text. I would like to apply this to the above situation. This way broken links can also be picked up, and reported to admin (a major advantage as they can then locate them and remove the link or add the product / page that it refers to).
I would like to take this to the stage where content of entire pages can be rearranged (kinda like web parts, but not as advanced as that). I mean like so you can put [layout type="3columnImageTopRight" image="imageurl"]Content here[/layout]. This will display, as specified, an image in the top right (with padding at the left and bottom) and 3 columns - maybe with the image spanning one or two columns). The imageurl can be specified as another token: maybe like [Image:imagename.gif] or something. This replaces it with the root to the image folder and then the specified filename. I have not really looked into how I am going to split the content into 3 columns yet, but this would be something to look at for my dissertation and then implement after my project deadline at least.
Does anyone have any ideas or pointers which could help me with this? Also if this is not strictly token replacement then please point me to what it is, so I can further develop this.
Thanks in advance,
Regards,
Richard Clarke
Hi,
I've a scenario where I need to bind to an interface - in order to create the correct type, I've got a custom model binder that knows how to create the correct concrete type (which can differ).
However, the type created never has the fields correctly filled in. I know I'm missing something blindingly simple here, but can anyone tell me why or at least what I need to do for the model binder to carry on it's work and bind the properties?
public class ProductModelBinder : DefaultModelBinder
{
override public object BindModel (ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType == typeof (IProduct))
{
var content = GetProduct (bindingContext);
return content;
}
var result = base.BindModel (controllerContext, bindingContext);
return result;
}
IProduct GetProduct (ModelBindingContext bindingContext)
{
var idProvider = bindingContext.ValueProvider.GetValue ("Id");
var id = (Guid)idProvider.ConvertTo (typeof (Guid));
var repository = RepositoryFactory.GetRepository<IProductRepository> ();
var product = repository.Get (id);
return product;
}
}
The Model in my case is a complex type that has an IProduct property, and it's those values I need filled in.
Model:
[ProductBinder]
public class Edit : IProductModel
{
public Guid Id { get; set; }
public byte[] Version { get; set; }
public IProduct Product { get; set; }
}
I'm calling a page method using .ajax() and it works in IE8 whatever the value of async is. However, in FF3.6, it only works with async set to false. When async is set to true, in Firebug, I just see status aborted. The page validates. I can work with async set to false, but any clues as to why FF can't work with async set to true?
$("[id$='_www']").click(function() {
var hhh = false;
$.ajax({
async: false,
cache: false,
type: "POST",
url: "/abc/def.aspx/jkl",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{ 'eee': '"
+ window.location.href.match(/\d{1,3}$/)
+ "', 'ttt': '"
+ $("[id$='_zzz']").val()
+ "' }",
success: function(msg) {
$("#ggg").html(msg.d);
},
error: function(xhr, err) {
hhh = true;
}
});
return hhh;
});
I'm starting a new project in MonoDevelop, and I want to see how other projects are using it.
I tried searching through SourceForge, code.google.com, etc., but mostly I was just finding things like add ins or something related to MonoDevelop itself.
So is there anyone else using MonoDevelop, especially open source?
Hi,
I want to use a SecureString to hold a connection string for a database. But as soon as I set the SqlConnection object's ConnectionString property to the value of the securestring surely it will become visible to any other application that is able to read my application's memory?
I have made the following assumptions:
a) I am not able to instantiate a SqlConnection object outside of managed memory
b) any string within managed memory can be read by an application such as Hawkeye
Hello,
I have a gridview control that has on onclick event bound to every cell. Once a user clicks on a cell it directs them to a booking confirmation page and passes 3 url variables. This booking page is behind a aspnet membership and thus if the user is not logged in they are served the login page. The login page has a redirect to https connection in the onload event using the IsSecure property. The issue is once the user logs in, then is returned to the booking confirmation page I lose 2 of the url vars.
If I remove the https redirect, everything works fine, but the user logs on on a http connection, which is not cool.
Appreciate and help
thanks
Reuben
Okay, so basically I want to be able to retrieve keyboard text. Like entering text into a text field or something. I'm only writing my game for windows.
I've disregarded using Guide.BeginShowKeyboardInput because it breaks the feel of a self contained game, and the fact that the Guide always shows XBOX buttons doesn't seem right to me either. Yes it's the easiest way, but I don't like it.
Next I tried using System.Windows.Forms.NativeWindow. I created a class that inherited from it, and passed it the Games window handle, implemented the WndProc function to catch WM_CHAR (or WM_KEYDOWN) though the WndProc got called for other messages, WM_CHAR and WM_KEYDOWN never did. So I had to abandon that idea, and besides, I was also referencing the whole of Windows forms, which meant unnecessary memory footprint bloat.
So my last idea was to create a Thread level, low level keyboard hook. This has been the most successful so far. I get WM_KEYDOWN message, (not tried WM_CHAR yet) translate the virtual keycode with Win32 funcation MapVirtualKey to a char. And I get my text! (I'm just printing with Debug.Write at the moment)
A couple problems though. It's as if I have caps lock on, and an unresponsive shift key. (Of course it's not however, it's just that there is only one Virtual Key Code per key, so translating it only has one output) and it adds overhead as it attaches itself to the Windows Hook List and isn't as fast as I'd like it to be, but the slowness could be more due to Debug.Write.
Has anyone else approached this and solved it, without having to resort to an on screen keyboard? or does anyone have further ideas for me to try?
thanks in advance.
note: This is cross posted from the XNA Creators Forums, so if I get an answer there I'll post it here and Vice-Versa
Question asked by Jimmy
Maybe I'm not understanding the question, but why can't you use the XNA Keyboard and KeyboardState classes?
My comment:
It's because though you can read keystates, you can't get access to typed text as and how it is typed by the user.
So let me further clarify. I want to implement being able to read text input from the user as if they are typing into textbox is windows. The keyboard and KeyboardState class get states of all keys, but I'd have to map each key and combination to it's character representation. This falls over when the user doesn't use the same keyboard language as I do especially with symbols (my double quotes is shift + 2, while american keyboards have theirs somewhere near the return key).
Hey everyone,
I'm wondering if anybody has run across something similar to this before. Some quick pseudo-code to get started:
<UpdatePanel>
<ContentTemplate>
<ListView>
<LayoutTemplate>
<UpdatePanel>
<ContentTemplate>
<ItemPlaceholder />
</ContentTemplate>
</UpdatePanel>
</LayoutTemplate>
<ItemTemplate>
Some stuff goes here
</ItemTemplate>
</ListView>
</ContentTemplate>
</UpdatePanel>
The main thing to take away from the above is that I have an update panel which contains a listview; and then each of the listview items is contained in its own update panel.
What I'm trying to do is when one of the ListView update panels triggers a postback, I'd want to also update one of the other ListView item update panels.
A practical implementation would be a quick survey, that has 3 questions. We'd only ask Question #3 if the user answered "Yes" to Question #1. When the page loads; it hides Q3 because it doesn't see "Yes" for Q1. When the user clicks "Yes" to Q1, I want to refresh the Q3 update panel so it now displays.
I've got it working now by refreshing the outer UpdatePanel on postback, but this seems inefficient because I don't need to re-evaluate every item; just the ones that would be affected by the prerequisite i detailed out above.
I've been grappling with setting up triggers, but i keep coming up empty mainly because I can't figure out a way to set up a trigger for the updatepanel for Q3 based off of the postback triggered by Q1.
Any suggestions out there? Am I barking up the wrong tree?
The code:
using (XmlReader xmlr = XmlReader.Create(new StringReader(allXml)))
{
var items = from item in SyndicationFeed.Load(xmlr).Items
select item;
}
The exception:
Exception: System.Xml.XmlException: Unexpected node type Element.
ReadElementString method can only be called on elements with simple or empty content. Line 11, position 25.
at System.Xml.XmlReader.ReadElementString()
at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadXml(XmlReader reader, SyndicationFeed result)
at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFeed(XmlReader reader)
at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFrom(XmlReader reader)
at System.ServiceModel.Syndication.SyndicationFeed.Load[TSyndicationFeed](XmlReader reader)
at System.ServiceModel.Syndication.SyndicationFeed.Load(XmlReader reader)
at Ionic.ToolsAndTests.ReadRss.Run() in c:\dev\dotnet\ReadRss.cs:line 90
The XML content:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/roller-ui/styles/rss.xsl" media="screen"?><rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
<title>Software architecture, software engineering, and Renaissance Jazz</title>
<link>https://www.ibm.com/developerworks/mydeveloperworks/blogs/gradybooch</link>
<atom:link rel="self" type="application/rss+xml" href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/gradybooch/feed/entries/rss?lang=en" />
<description>Software architecture, software engineering, and Renaissance Jazz</description>
<language>en-us</language>
<copyright>Copyright <script type='text/javascript'> document.write(blogsDate.date.localize (1273534889181));</script></copyright>
<lastBuildDate>Mon, 10 May 2010 19:41:29 -0400</lastBuildDate>
As you can see, on line 11, at position 25, there's a script block inside the <copyright> element.
Other people have reported similar errors with other XML documents.
The way I worked around this was to do a StreamReader.ReadToEnd, then do Regex.Replace on the result of that to yank out the script block, before
passing the modified string to XmlReader.Create(). Feels like a hack.
Has anyone got a better approach? I don't like this because I have to read in a 125k string into memory.
Is it valid rss to include "complex content" like that - a script block inside an element?
Thanks.
I have been having issues trying to return distinct records from a subsonic3 query using VB. My base query looks like so:
Dim q As New [Select]("Region")
q.From("StoreLocation")
q.Where("State").IsEqualTo(ddlState.SelectedValue)
q.OrderAsc("Region")
This returns duplicates. How can I add a distinct clause in this to return distinct records? I have been trying to place around with Contraints, but to no avail.
Thanks in advance
HR
I have this:
[Display(Name = "Empresa")]
public string Company{ get; set; }
In my aspx I have:
<th><%: Html.LabelFor(model => model.Company)%></th>
And this generates:
<th><label for="Company">Empresa</label></th>
Are there any html helper extensions to only show the display attribute without label, only plain text? My desired output is this:
<th>Empresa</th>
Thanks!
EDIT
I tried DisplayFor or DisplayTextFor as suggested, but they are not valid because they generate:
<th>Amazon</th>
They return the value of the property... I want the name from the Display attribute.
The code has a runtime dependency which is not available in our development environment (and is available in test and prod). It's expensive to actually test for the dependency, and I want to test for the environment instead.
if (isDevEnvironment) {
// fake it
}
else {
// actually do it
}
Without using appSettings, what code/technique/test would you use to set isDevEnvironment?
Example answers:
check machine name (partial or full)
check for running instance of Visual Studio
check for environment variable
I'm hoping for a test I hadn't considered.
When trying to load Microsoft.Xna.Framework.dll from any project, it throws a FileNotFoundException. The specified module could not be found. (Exception from HRESULT: 0x8007007E), with no innerException.
Even the simple code like the following throws that exception:
static void Main(string[] args)
{
Assembly.LoadFile(@"C:\Microsoft.Xna.Framework.dll");
}
I run XP x64, but I've set the platform in the configuration manager to x86, because I know it shouldn't(doesn't) work on x64 or Any CPU.
I've manually added the dll file to GAC, but that didn't solve the problem. I have also tried the M$ Assembly Binding Log Viewer to see if those logs had any useful information, but they didn't. Everything, the loading etc, was a success according to them.
Any suggestions? please?
I've been noticing a pattern with ReSharper (both 4.5 and 5).
Very often (almost always) when I have solution-wide analysis turned on, and WPF code in my solution, ReSharper will mark a number of the .xaml.cs files as being broken.
When I navigate to the file, sometimes it magically updates and displays no errors, and other times I have to open other files that are not being correctly read and close them again to force resharper to correctly analyze them.
I assume it has something to do with the temporary .cs code that is generated with XAML, but does anyone know why this is actually happening, and if there is a work around? Should I just file a bug report with JetBrains? Does anyone else experience this?
We are using a WebBrowser control in our win forms application which is running in terminal services. IE 7 is the browser that is installed for the session. We are using WebForms to generate the web pages.
If we try and submit a web page in the WebBrowser control it does not work. The submit button does not push down.
If we try and submit a web page in IE 7 that is installed on the same machine it works as expected.
This is only an issue for one person. The WebBrowser control is working for other users.
Any thoughts on how I can debug why the submit button is not submitting for the WebBrowser control?
Thanks in advance.