|
An Interface just defines what Methods / Properties / Events etc must be publicly available, how to achieve it is the responsibility of the class. So the person Interface might look like:
public Interface IPerson
{
int Id { set; get; }
int Name { set; get; }
int PassportNumber { set; get; }
int Nationality { set; get; }
void SomeFictionalMethod();
}
Note that the Interface declares public members, so you don't (in fact can't) state the visibilty. You can Generate a Interface by right-clicking on the class name --> Reafactor --> Extract interface.
You don't have to use an Interface, but it is good practise. I can't think of a meaningful explanation for your example, so here's a simplified one. Let's say you have need to model modes of transport, that all expose two methods Go And Stop . A horse is a mode of transport, but so is a car, the implementation of these would be totally different so a common base class doesn't make sense. The solution that makes the most symantic sense is to create and IModeOfTransport interface and have both the Horse and Car implement it. Now let's suppose your Person object needs a ModeOfTransportProperty you can Declare it:
public class Person : IPerson
{
public IModeOfTransport {get; set;}
}
Now you can pass any object in the inherits from IModeOfTransport , even if they don't have the same base class, this help to decouple the code.
|
|
|
|
|
Dear All,
I have two web pages, say SourceWebPage and TargetWebPage, on the TargetWebpage I have a directive like:
<%@ PreviousPageType VirtualPath = "~/SourceWebPage.aspx" %>
These are the code behand on TargetWebPage Page_Load Event:
if (!Page.IsPostBack)
{
if (Page.PreviousPage != null && Page.PreviousPage.IsCrossPagePostBack)
{
DateTime reportDate = PreviousPage.DTReportDate;
string serialNo = PreviousPage.SerialNo;
}
else
{
LoadReportType();
odsSyncSummaryReport.FilterExpression = GetObjDSFillerExpression();
gvSyncSummaryReport.DataSourceID = "odsSyncSummaryReport";
gvSyncSummaryReport.DataBind();
}
}
else
{
odsSyncSummaryReport.FilterExpression = GetObjDSFillerExpression();
}
there is a link button on SourceWebPage like this: OnClick = "lbSerialNo_Click" PostBackUrl = "~/TargetWebPage.aspx".
Both pages are able to be accessed by click on the menu, when I go to SourceWebPage first and then click the link button, it posts back to the TargetWebPage and everything works fine. But the problem is when i go to the TargetWebPage first, it throws an exception.
I think i know the problem because the PreviousPage property (SourceWebPage) hasn't been loaded yet, therefor there is no way that the TargetWebPage to get the value from SourceWebPage. What i want to know in here is how do I know whether the TargetWebPage is posted from SourceWebPage or it is posted from Menu. This piece of code doesn't help me at all: if (Page.PreviousPage != null && Page.PreviousPage.IsCrossPagePostBack)
I was googling for hours but without any luck, can someone in here shed me a light?
Thanks
|
|
|
|
|
You could check the HTTP_REFERER server variable.
Also, please remember to format any code you post using pre tags
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks a lot mate, your post does help me and to help the others further, this is the code (in c#) that does the trick:
if (Request.ServerVariables["HTTP_REFERER"].EndsWith("xxx.aspx"))
|
|
|
|
|
Hi,
I learned that, if I use image height and image width attribute in html than, the page loads faster because the internet explorer wont need to calculate the image dimension. So, in my ASP.NET code behind file, I calculate the image from server and render html code with appropriate height and width attribute for image. Now, I am wondering, if I dont calculate the image height and image width in server and let the browser calculate it on the fly when rendering, will that be more efficient ?
Here is my code that I used to get Image Size in Server:
public static Size GetImageDimension(string absolutePath)
{
byte[] imageData = File.ReadAllBytes(absolutePath);
var fullSizeImageHeight = -1;
var fullSizeImageWidth = -1;
MemoryStream origStream = null;
System.Drawing.Image fullSizeImg;
try
{
origStream = new MemoryStream(imageData);
fullSizeImg = System.Drawing.Image.FromStream(origStream);
fullSizeImageHeight = fullSizeImg.Height;
fullSizeImageWidth = fullSizeImg.Width;
}
catch
{
}
finally
{
if (origStream != null)
origStream.Dispose();
}
return new Size(fullSizeImageWidth, fullSizeImageHeight);
}
|
|
|
|
|
In my opinion, calculating the image dimensions on server side means doing I/O operations for each image request, so its better we ask individual client (i.e. browser) to do that. In that case your web server will not have that much load but yeah the browser may take some more seconds.
If you are not criticized, you may not be doing much.
'Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.' Robert Heinlein (1907 - 1988)
|
|
|
|
|
Hi,
Thanks for your reply.
Actually I am concerned about the overall speed,
So, let assume that, the time taken in server for FILE IO operation and image size calculation is = Ts
And the time taken in client for image size calculation on the fly is = Tc,
I need to know, if Ts > Tc or Ts < Tc.
If Ts < Tc, I will use server side code to calculate image size, I dont care about server load as the page I am rendering is a protetected page, only one user can see that page.
If Tc < Ts, then, I will let the browser calculate and display the page.
So, can you please tell me which value is higher ? Ts or Tc ?
It is very hard to experiment and find out these values, so I thought if this information is already known by others, it would be helpful.
Regards.
|
|
|
|
|
Hi,
I am fairly new to asp.net and need a bit of help please. In our project we are doing a callback from the client-side to the server side using a webmethod in order to try and keep the page request alive. From what I can see in Firebug is that, on the server side, the webmethod is triggered successfully from the javascript until I start with my async event on the server side, then the webmethod waits for it to be finished before the javascript calls the pagemethod again.
However this process of ours can take anything from 1 minute to 40 minutes, so it is quiet essential that I keep the page request alive. I don't want to increase the timeout on the scriptmanager since I don't think that is the right way to approach this issue.
Here is a small sample of how the code code is:
Java script:
function SimpleCallback() {
var lCurrentStatus = PageMethods.GetCurrentStatus(ProcessResults);
}
function ProcessResults(pCurrentStatus) {
if (pCurrentStatus != "Completed") {
window.setTimeout("SimpleCallback()", 100);
}
}
function SaveButtonClick(pArgument) {
var lAjaxManager = $find("<%= MyAjaxManager.ClientId %>");
lAjaxManager.ajaxRequest(pArgument);
SimpleCallback();
}
<asp:Button ID="SaveButton" runat="server" Text="Save" OnClientClick="return SaveButtonClick('SaveStuff');"
Server side code:
[WebMethod]
public static string GetCurrentStatus()
{
return FCurrentStatus;
}
protected void MyAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
if (e.Argument == "SaveStuff")
{
FCurrentStatus = "ProcessRunning";
SaveInformation();
}
}
delegate void MyLongRunningProcess();
private void SaveInformation()
{
var lLongRunningMethod = new MyLongRunningProcess(NextClass.Save());
IAsyncResult lResult = lLongRunningMethod.BeginInvoke(null, null);
while (!lResult.IsCompleted)
{
}
lLongRunningMethod.EndInvoke(lResult);
}
Is there a way of doing the pagemethod call from javascript asynchronously, since it seems this is my problem. Or is there another way of approaching this in order to keep the page request alive?
Thank you in advance,
David.
|
|
|
|
|
Calling the pagemethod is essentially asynchronous since it is out of band and the user can continue to interact with the page.
Typically one places some type of progress indicator on the page while waiting for the out of band call to complete. Look here[^] for an idea
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
40 minutes?! Surely you don't expect the user to hang around while that happens...? It doens't matter what code you use if they simply shut their computer down...
..on the assumption that all that matters is that your long running process is initiated by them, but they don;t need to wait for the result (you could always show it to them next time they log on), then you can accomplish this by calling a new HttpWebRequest, whcih will run in a new thread and won't be affected by what the user does once it is invoked. You will, by the sound of it, need to set/increase the ScriptTimeout property of your long running process.
Place your long running process in a generivc handler ("longrunning.ashx"), then call this from your server-side code as follows:
Dim rq As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create("longrunning.ashx"), System.Net.HttpWebRequest)
rq.Method = "POST"
rq.ContentType = "application/x-www-form-urlencoded"
Dim postData As String = "" ' any data that needs to be passed to the handler
rq.ContentLength = postData.Length
Dim writer As New System.IO.StreamWriter(rq.GetRequestStream(), System.Text.Encoding.ASCII)
writer.Write(postData)
writer.Close()
Note that you should specify the full URL (http path) to "longrunning.ashx", not just the handler filename as I have above.
I can only giove you VB code for this I'm afraid - after that you;re on your own...
|
|
|
|
|
I want to place news and highlights and articles links on my website so I find or receive any interesting news or article I will put the title and url on my website.
I first thought to have a form to post it with txtTitle and txtURL textbox but then I had another idea and I want your advise please
I will create an email account then send the article title to that email address with article title in subject and article url in body
This will be easier to post especially when posting from mobile device
What do you think?
Also how can read the article title and url once received in inbox and save it into sql server article_title and article_url fields?
|
|
|
|
|
I have a main_menu.ascx web control placed in my root and contains my website navigation menu with NavigationURL to the pages
I have my root files and I included the ascx file there
Until here, I have no issue
Now!
I have sub folders in my root and I want to include same ascx file because I don't want more than one main_menu file!
But the problem here is with the NavigationURL because it will be different when the aspx file is in sub folder
How can make sure my NavigationURL is referring to the correct path whether aspx in root or in sub folder?
|
|
|
|
|
Why not use a masterpage? Also, you don't need to have multiple user controls that do the same thing, just change the data that is used to construct/populate it
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I want where should I place the Response.Expires?
1. Global.ascx application_srart, application_end, session_start, session_end?
2. Default.aspx.cs Page_Load?
And in case of both should I place before any code or after all codes?
|
|
|
|
|
|
Hi
I am including some code in the web.config file. But I am wondering if i could include those code inside the code behind in ascx or ascx.cs file without writing directly to the web.config file. Is it possible ?
suchita
|
|
|
|
|
Sorry what?
Code should be in your codebehind file (.cs) configuration should be in your configuration file (hence web.config) so could you please rephrase the question?
|
|
|
|
|
i mean the things which we write in web.config file, can we do it from code behind ?
suchita
|
|
|
|
|
|
Is this the way I can avoid conflict between the same application I can call from two different projects and not affect each settings?
For example I have one editor and I am using that editor from different portlets with some modification. So if i not put the information in web.config file about that editor, it wont affect me using that editor in different portlets right ?
suchita
|
|
|
|
|
web.config global to the virtual directory hosting the app. You can make some settings specific to individual folders within the app. If the you have two separate applications, or virtual folders, this will work, but you need to replicate the code between each instance, which adds headaches to maintainability and support.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
yes right. So what would be the best way to get through it ?
suchita
|
|
|
|
|
Without knowing your requirements, intentions, skills, deployment base, etc. it is an impossible question to answer.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
ok. Let me describe one more time. I have an editor which i am using from different portlets and for those different portlets the web.config file is same. But i am using editor with some modifications in those portlets as required. So When I include that key for that editor in web.config, it will be the same for all those editor which is what i wanted to avoid. So I am asking Is there any way to avoid this? Is there anyway i can do in code behind? Or is there any good smart way to do this? What are my options and which one will be the best way to do this ? Right now i am keeping this in web.config file.
suchita
|
|
|
|
|
Are you a developer? Can you write code?
I know the language. I've read a book. - _Madmatt
|
|
|
|