SPL and PHP allows you to create objects on the fly from classes, that fulfill certain conditions, such as implementing certain interfaces and stuff like that.
However, I would like to do something similar in c# and automatically create objects from all classes in a namespace and invoke a particular method from those classes that implement a certain interface.
My experience developing desktop apps is very limited. I am not quite sure if I should use delegates to archive this or if reflection is really the way to go.
Basically all pages on this site I am building cannot be accessed when the user clicks on "Back" (or with key control) in the browser, and the page should expire if one is trying to navigate back in history.
I put into Global.asax::Application_BeginRequest
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1))
Response.Cache.SetValidUntilExpires(False)
Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches)
Response.Cache.SetNoStore()
This would clear out the cache and disallow going back to any pages when the user is logged out, but doesn't do the job while the user is logged in.
I saw posts where people suggested using a javascript approach, by calling
History.Forward(1)
on the page. But I wouldn't like to do this, as it will require javascript enabled to work (which user can disable).
Appreciate any suggestions.
I want to pass the sessionID as a json parameter, I can see how to override SessionIDManager and such, but this just covers custom creation/validation of sessionID's as opposed to where it actually gets the sessionID from.
There is of course 'cookieless' which puts it in the url, but that doesn't work for me either.
So i'd like to override the session handling so I can specify where it should look for the sessionID.
Let's say I have a custom object of Foo
Is there anyway I can sort through a list of these objects, like
list<of foo>.sort()
and also be able to sort this list with a passable parameter. which will influence the sort?
list<of foo>.sort(pValue)
I'm guessing I'll need to define two separate sorts, but I am not sure.
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?
Hello, I'm creating an html page that is posted to another page for processing. I don't want users to see the weird URL they are redirected to and I was using FRAMES but I can't figure out how to add my HTML page dynamically because I need the variables and either add frames or try another way to accomplish this. So, based on how I'm creating the page below, how can I hide the URL and add something that I want.
Here is how I'm creating the page.
StringBuilder sb = new StringBuilder();
sb.Append("<html><head></head>");
sb.Append("<body onload=\"document.frmLaunch.submit();\">");
sb.Append("<form name=\"frmLaunch\" action=\"" + variableTargetURL + "\" method=\"post\">");
sb.Append("<input type=hidden name=\"testVariable\" value=\"" + variableTest + "\">");
sb.Append("</form>");
sb.Append("</body></html>");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Write(sb.ToString()); response.End();
I have created a new control VidController
public class VidController : Controller
{
public ActionResult GetVids()
{
return View();
}
}
Right clicked inside the method and created View with default name GetVids. Now when i try to open ~/VidController/GetVids there is no page opening...
What i have to set in Global file?
Okay so given a LinkButton inside a the ItemTemplate of a Repeater declared like this -
<asp:LinkButton ID="restrictionDelete" runat="server" CssClass="restrictionDelete" Text="Delete..."
OnCommand="lnkDeleteRestriction_Command" CommandName="Delete" CommandArgument="<%# Container.DataItem %>"></asp:LinkButton>
Now,..the repeater is being bound to a list of Restriction objects so when the lnkDeleteRestriction_Command is fired I'm expecting that I can cast the CommandEventArgs.CommandArgument which is an object to my Restriction type. This doesn't seem to be so,..I just get the fully qualified type name as a string.
Can I receive a typed command argument at all and if not, why is it an object?
Thanks in advance,
Hi,
This thing is driving me nuts. I have a UserControl that is called WebUserControl.
I need to cache this control, so I put the following in the WebUserControl.ascx:
<%@ OutputCache Duration="240" VaryByParam="FeedName" %>
Then I have the Default.aspx file in which I have:
<div class="divInnerLeft" id="L1" runat="server">
<uc1:WebUserControl FeedId="a1" ID="a1" runat="server" FeedName=""/>
</div>
<div class="divInnerMiddle" id="M1" runat="server">
<uc1:WebUserControl FeedId="a3" ID="a3" runat="server" FeedName=""/>
</div>
In the Page_Load event I set the FeedName property - according to the user preferences.
The problem is that after initially loading the page, the controls are generated OK. But then, in the Page_Load event they are not available again. So the a1 and a3 are null and I cannot set the FeedName for different user.
How to solve this?
Thanks!
Hi,
I have a few items apart of my Web.sitemap file that rely on querystring or session variables.
I do not want these items to appear in my menu.
Is there a way to hide it from the menu, but still be in the sitemap (for sitepath control).
Thanks
I need to determine if I'm on a particular view. My use case is that I'd like to decorate navigation elements with an "on" class for the current view. Is there a built in way of doing this?
I have a table with rows in, and each row has a few <td> elements. The last element has a checkbox in.
They are in a <div> which is set to runat="server". I have another checkbox on the page called "chkAll" that when clicked, I want to javascript check or uncheck all of the checkboxes in my table.
I'm not very good at Javascript, so I am not sure what to do. I added a javascript onclick method, and put document.getelementbyid and put in the div.clientID, but I wasnt sure what to do from there. Any ideas?
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 am trying to use TimeSpan as a parameter type for an action in a controller, but the value is always now, so I presume it is not parsed correctly by MVC. The value that gets sent to it is "7:00 PM". Is it possible to make MVC support such format? I am using MVC 2.
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!
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?
Hi All,
I am using two frames to display pages. The page url is given in codebehind. But it is not reflecting. If i click f5 its grtting reflected.
Needs:
How to refresh a frame after setting the src value in the code behind.
code: topFrame.Attributes["src"] = "MainPage.aspx";
Geetha.
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);
}
}
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?
I want to have a property on my custom control that is an interface type. For example:
[
ToolboxData("<{0}:MyTextBox runat=server></{0}:MyTextBox"),
ParseChildren(true, "Validation")
]
class MyTextBox : WebControl
{
[
Category("Behavior"),
Description("The validation to use"),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty)
]
public IValidation Validation { get; set; }
}
Then when I go to use my control in a web form I would like to be able to do:
<my:MyTextBox ID="txt" runat="server">
<my:FancyValidator />
</my:MyTextBox>
That way I will be able to define one class that could use any number of validators. When I try and do this now, I end up with an error saying:
Type 'IValidator' does not have a public property named 'FancyValidator'
What do I need to do to make this work?
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 got the following :
01.05.03
I need to convert that to 1.5.3
The problem is I cannot only trim the 0 because if I got :
01.05.10
I need to convert that to 1.5.10
So, what's the better way to solve that problem ? Regex ? If so, any regex example doing that ?
I've been given a task to make a dynamic drop down which takes it's data[image and value id] from table. I am wondering if any of you came across this scenario or if any one can help me out in this I need help in concept and coding. Definitely any help is appreciated.
I see the example in jquery here is the link:
http://www.marghoobsuleman.com/jquery-image-dropdown
something like this but data is coming from table.
I have applied DataAnnotation based validations to two of my properties like this
[Required(ErrorMessage = "Title is required")]
public string Title { get; set; }
[Required(ErrorMessage = "Description is required")]
public string Description { get; set; }
Here is the view page's code
@Html.LabelFor(model => model.Obj.Title)
@Html.EditorFor(model => model.Obj.Title)
@Html.LabelFor(model => model.Obj.Description)
@Html.TextAreaFor(model => model.Obj.Description)
The Problem is that on click of submit button, on client side (js) its only giving me error for for Title and not for the Description. But Its giving me validation error for the Description after the postback.
What possible causes?