|
You should have searched the CP articles first. Check this[^] out.
|
|
|
|
|
|
Hello everyone,
I am trying to practice regarding OOP. I got a code from internet
public class StoreIndexViewModel
{
public int NumberOfGenres { get; set; }
public List<string> Genres { get; set; }
}
as I am beginner, I am trying to develop code in the way I learn.however it is not professional way.
this is my code regarding above code
namespace TestProject.ViewModels
{
public class StoreIndexViewModel
{
public int _numberofgenre;
public List<string> _genres;
public int Numberofgenre
{
set { _numberofgenre = value;}
get { return _numberofgenre; }
}
public List<string> Genre
{
set { _genres = value; }
get { return _genres;}
}
public StoreIndexViewModel(int numberofgenre,List<string> genre)
{
this._numberofgenre = numberofgenre;
this._genres = genre;
}
Could you please tell me did I write correct code?
thx for your help.
modified on Saturday, August 28, 2010 8:00 AM
|
|
|
|
|
future3839 wrote: Could you please tell me did I write correct code?
Correct in what sense? If it compiles, it is syntactically correct. You can check that yourself. If it does what you want it to do, it is logically correct, may not be the best/optimum logic though.
I think you should describe what do you mean by correct.
Anyways, here are a few things that you may consider:
1. If you are using .Net 3.0 or above, make use of automatic properties.
2. You can make use of XML comments and regions in stead of commenting using "//".
3. You can make your fields private and have them only when it is really needed.
4. No need of having "this" keyword unless really needed.
5. Make use of Generic lists or Collection since they are strongly typed.
modified on Saturday, August 28, 2010 11:14 AM
|
|
|
|
|
future3839 wrote: //definition of Fields
public int _numberofgenre;
public List _genres;
Your field definition need to be private . You have public accessors.
|
|
|
|
|
In addition to the other comments you should use the properties rather than access the fields directly
this._numberofgenre = numberofgenre;
Should be
Numberofgenree = numberofgenre;
This way any logic that needs to be executed when a property is accessed will not be by-passed. Also, if the backing field changes it will not affect the code.
Most coding standards also dictate the use of Pascal casing for properties and methods
Numberofgenre => NumberOfGenre
Many also prefer fields to begin with m_
public int _numberofgenre; => public int m_NumberofGenre;
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I am just trying to learn JQuery.
I want to try out a basic JQuery example. Adding items from one list box to another.
It works fine in the normal aspx page (I pasted it in Default.aspx in root directory).
I placed JQuery Libraries in a folder Javascript under root.
This works fine.
Then I created a WebUserControl and placed the same code and I registerd this user control in default.aspx.
The page loads , but when I click on Add it does not move items from one list to another.
While in the aspx page, I checked the Watch and
innerHTML of the context->childNodes has values "Delhi, Bombai ..........". Same as OuterHTML.
But in the user control with the same code as pasted below.
innerHTML is "" and OuterHTML is "<HTML4F>"
Please throw some light to this
See the code below:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="User_Controls_WebUserControl" %>
<script src="../Javascript/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
debugger;
$("#add").click(function () {
debugger;
$("#fromListBox option:selected").appendTo("#toListBox");
});
$("#addAll").click(function () {
$("#fromListBox option").appendTo("#toListBox");
});
$("#remove").click(function () {
$("#toListBox option:selected").appendTo("#fromListBox");
});
$("#removeAll").click(function () {
$("#toListBox option").appendTo("#fromListBox");
});
});
</script>
<table>
<tr>
<td><asp:ListBox ID="fromListBox" runat="server" SelectionMode="Multiple" Rows="6">
<asp:ListItem>Delhi</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Pune</asp:ListItem>
<asp:ListItem>Kolkata</asp:ListItem>
<asp:ListItem>Mumbai</asp:ListItem>
<asp:ListItem>Bangalore</asp:ListItem>
</asp:ListBox></td>
<td> <input id="add" type="button" value="Add" /><br/>
<input id="addAll" type="button" value="Add All" /><br/>
<input id="remove" type="button" value="Remove" /><br/>
<input id="removeAll"type="button" value="Remove All" /><br/></td>
<td><asp:ListBox ID="toListBox" runat="server" SelectionMode="Multiple" Rows="6"></asp:ListBox> </td>
</tr>
</table>
modified on Saturday, August 28, 2010 6:03 AM
|
|
|
|
|
afsal qureshi wrote:
Are you sure there is no changes in javascript script file path after moving your code to user control ?
|
|
|
|
|
I don't think so. I picked up the Src value from the source selector popup.
For Clarification,
JQuery-1.4.1.js resides in stays in Javascript folder in root.
User Control stays in User Control folder and default page stays in the test folder.
Also if path is inorrect we would have got a javacript runitime error
modified on Saturday, August 28, 2010 1:33 PM
|
|
|
|
|
Have you checked the ids that are being rendered are the same you are looking for? Remember the name mangling that ASP.NET applies.
You can check it like this
$("select[id$='fromListBox'])
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi,
im developing a webapplication where i dont want to have a minimize and maximize buttons of the startup page.and i also dont want the menu bar also.
it is urgent requirement for me.
thanks in advance.
|
|
|
|
|
vishnukamath wrote: im developing a webapplication where i dont want to have a minimize and maximize buttons of the startup page.and i also dont want the menu bar also.
Your question is not clear. What do you mean by startup page ? About which menu bar you are talking about ?
vishnukamath wrote: it is urgent requirement for me.
First of all be specific with your requirments and represent it well so that any one can understand and give you answer as quick as possible. Other wise it would be quite difficult to answer.
|
|
|
|
|
hi,
im designing a login page,when i run my application it is the first page that will appear on screen.
now i have a requirement that my login page should not have the menubar(file,edit,view,etc..) and the minimize and maximize buttons should not work.
this is an urgent requirement.hope you understand.
thanks in advance.
|
|
|
|
|
|
hi,
i tried with window.open
and if i use window.open the result will be another window opening, but i need to display my login window without menubar and maximize and minimize buttons.please suggest me better way to do this.
thanks and regards,
vishnu.
|
|
|
|
|
|
in my project i had a gridview and in the gridview ihad a templatefeild in which i had a file upload control and a button control. while clicking on button the fileupload control should read the filename. but we are getting the null value for filename.
any suggestions plz............
thanks in advance............
|
|
|
|
|
Are you doing it on the client side (using JavaScript) or on the server side (doing a postback on button click)?
Can you give the code that you used, without which it would be difficult to identify the issue?
..Go Green..
|
|
|
|
|
vishnukamath wrote: while clicking on button the fileupload control should read the filename. but we are getting the null value for filename.
Where is your source code ? have you checked with FileUpload1.PostedFile.FileName ? And also make sure you are check the Postback option !
Let me know if the problem is still there.
Thanks !
|
|
|
|
|
hi,
My issue fixed and thank you for your suggestions.
Thanks & Regards,
Vishnu.
|
|
|
|
|
Hi All
I have byte arrry which is saved into the data base we converted text to byte array using Itextsharp dll but when i getting this byte array from the data base how to convert it into the text format
I have already tried the below following way.
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
return enc.GetString(input);
also tried
System.IO.MemoryStream memo = new System.IO.MemoryStream(pdfByteArray);
System.IO.StreamReader reader = new System.IO.StreamReader(memo);
string text = reader.ReadToEnd();
can u guys suggest another way to do this.
Thanks
amit patel
|
|
|
|
|
Did you triede Convert.ToBase64String ?
|
|
|
|
|
Without knowing what method you called to go from text to byte[] there is no way to know for sure how to get it to go the other way. If the call you used actually turned the text into a PDF file and gave you the bytes of the pdf, then you need to use ITextSharp to parse the pdf to get the text back out. If you don't want to convert the text to a pdf before saving, then I would certainly recommend using standard .Net library calls rather than iTextSharp to convert to byte[] (e.g. enc.GetBytes(yourString)).
|
|
|
|
|
hello all,
i have a problem in source code .i am developing a multilingual website. Here i am using Global resource file for translation .It is working fine in local server but when i upload into online server the following error shows .Below shown bold part a label contains value that dynamically getting from code file .for working online why this value not getting any problem with java script or resource file accessing problem
Server Error in '/' Application.
--------------------------------------------------------------------------------
Cannot use a leading .. to exit above the top directory.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot use a leading .. to exit above the top directory.
Source Error:
Line 384: mm_menu_0315125553_7.addMenuItem(" <%=lblPrecisionAdvertising.Text%>","location='http://KosmosPrecisionAdsTester.com/HPA_PresentationLayer\1_INTRODUCTION\701-...the-market-of-1.aspx'");
Line 385: mm_menu_0315125553_7.addMenuItem(" <%=lblMarketOf1.Text%>","location='http://KosmosPrecisionAdsTester.com/HPA_PresentationLayer\1_INTRODUCTION\701-...the-market-of-1.aspx'");
Line 386: mm_menu_0315125553_7.addMenuItem(" <%=lblUNIQUESystems.Text%>","location='http://KosmosPrecisionAdsTester.com/HPA_PresentationLayer\1_INTRODUCTION\702K-UniqueSystems.aspx'");
Line 387: mm_menu_0315125553_7.hideOnMouseOut=true;
Line 388: mm_menu_0315125553_7.bgColor='#0082AF';
Source File: c:\inetpub\wwwroot\KosmosClub.com\MasterPage.master Line: 386
Stack Trace:
[HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.]
System.Web.Util.UrlPath.ReduceVirtualPath(String path) +11248521
System.Web.Util.UrlPath.Reduce(String path) +64
System.Web.UI.Control.ResolveClientUrl(String relativeUrl) +212
System.Web.UI.HtmlControls.HtmlLink.RenderAttributes(HtmlTextWriter writer) +85
System.Web.UI.HtmlControls.HtmlLink.Render(HtmlTextWriter writer) +57
ASP.masterpage_master.__Render__control2(HtmlTextWriter __w, Control parameterContainer) in c:\inetpub\wwwroot\KosmosClub.com\MasterPage.master:386
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115
System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer) +23
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Page.Render(HtmlTextWriter writer) +38
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240
|
|
|
|
|
I think the name of the configurable aspx website is the problem '701-...the-market-of-1.aspx'.
The function System.Web.Util.UrlPath.ReduceVirtualPath(String path) tries to reduce the paths '..'-value to the
upper directory. Your path is an absolute path. Now the function has the problem to find the upper directory of the full root directory. This directory doesn't exist and thats why it spits this exception.
Greetings
Covean
|
|
|
|