Declaring Variables Without As, Bad Practice?

Oct 20, 2010

I just noticed that I can save a lot of spacing by not using "as" when declaring variables, in some cases (not sure if this is something new in VS2010). For example:

Dim Name as string = "Bob"

works the same as:

Dim Name = "Bob"

I prefer the latter as some of my type declarations can be very long due to the library I am working with, and omitting the types simplifies the lines and makes them more readable. I am wondering a few things:

1. Do the two methods function at all differently?

2. Is this a bad practice, or generally excepted?

3. Is there a name for this?

View 1 Replies


Similar Messages:

What Is The Best Practice Of Declaring The Variables

Oct 7, 2010

I just want to know the declaration of variables in a separate class file or declaring in the same aspx.cs file. the best practice of declaring the variables.

View 3 Replies

Best Practice For Tracking State And Session Variables?

Apr 12, 2010

We're creating a new consumer/public-facing ASP.Net web app. There are two concerns:
--Use cookie or cookieless forms authentication?
--If we decide not to use cookies at all, how would you store the data that would otherwise be stored in the cookie (Customer ID, AffiliateID, etc.). Does the ASP.Net authentication framework track something like CustomerID?

View 2 Replies

Declaring A Constructor Private Or Declaring A Class Sealed Is Same Thing?

Oct 12, 2010

Is declaring a constructor private or declaring a class sealed is same thing?

View 1 Replies

Collect 2 Variables From One Hyperlink, And Use Those Variables In The Page_load To Set As Session?

Aug 8, 2010

i am trying to collect 2 variables from one hyperlink, and use those variables in the page_load to set as session. but i don't know how to collect those 2 variables

such :

<a href="javascript:;" onclick="wsChangeColor('mainData', '#FF0000','#FFE4E1');return false;" title="Change color" id="red">1</a>

i would like to collect '#FF0000','#FFE4E1' or direct set '#FF0000','#FFE4E1' to string then send to pageload, how can i do this by only clicking on it ?

View 1 Replies

Web Forms :: Storing Javascript Variables Into C# Variables

Jan 2, 2010

I have this code in javascript: var x = e.mapX; It gets the X-coordinate of a map. What I want to do is that I want to store this into a c# variable. I have a class named Test with an integer property X. I want to store var x into X. In the codebehind, I have this on the Page_Load: Test test = new Test(); Then I am trying this on the javascript code: var x = e.mapX;

View 16 Replies

Declaring List In Web Service?

Jan 9, 2010

Why is it that I cannot declare List in my web service using asp.net just like what I got on a certain site.

Code:

List<string> responses = new List<string>();

View 1 Replies

.net - Declaring Gridview Selectcommand?

Nov 9, 2010

When the page loads, the GridView (located in an update panel) should be loaded with my first SQL SELECT statement. On the button click, the same GridView will be loaded with new data.

What am i doing wrong? On startup, the GridView doesn't appear.

Public cmd As New SqlCommand()
Public percentp As New SqlCommand()
Public da As New SqlDataAdapter(cmd)[code].....

View 3 Replies

C# - Declaring Parameter That Don't Want To Pass?

Jul 14, 2010

public Jquery Extra(this HtmlHelper htmlhelper,
string message,
IDictionary<string, object> htmlAttributes)

if i declare the this Htmlhelper htmlhelper when i declare my method, but i don't want to pass that parameter in when i call the method?

View 3 Replies

Declaring Scalar Variable

Jan 23, 2013

I have a really simple web interface which has been created in visual studio 2010 and is connected to an SQL server running MS SQL Server 2008. I essentially want the user to be able to enter values into the two text boxes provided and when the button is clicked, these values are inserted into the relevant table in the database.

When I run the code, I get an error back saying that the 'scalar variable for @clientName is not defined.' I have altered the insert statement to fixed values rather than entering from the text boxes and this works fine (ie, replace @clientName and @serverName in the insert statement with 'xx' and 'yy' respectively). How I can define these scalar variables. I'm not to sure what i'm missing. Code below.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

[Code] .....

The code that the button executes is below

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
SqlDataSource1.Insert()
End Sub
End Class

View 3 Replies

C# - Declaring A Global Variable In Codebehind?

Mar 18, 2011

I want to declare a Dictionary<string, object> variable but don't know where/how to. The values in the dictionary will be objects from the Page (ListBoxes, DropDownLists, etc) so I can't exactly create a class somewhere else. Is there any way I can make this variable accessible from each method in the codebehind?

View 5 Replies

C# - Declaring A Session Dictionary In A Master Page?

Jan 29, 2011

How do you declare a dictionary called MyDic in the master page?

I want MyDic to hold lists of objects MyObj with a date as the key so that I can write something like this: "get the list for date 1/28/2011 from MyDic" or "put this list of MyObj from 1/28/2011 in MyDic".

I'd like to declare the dictionary in the master page so that I can access it in every page.

View 3 Replies

DataSource Controls :: Declaring New Sql Connection Failed?

Jan 13, 2010

I got a simple SQL Connection which works fine under VS 2005, once I convert to VS 2008, is failed to work. I even re-build entire apps from scratch under VS 2008, yet it still failed.

Here's the code.

[Code]....

The code failed at this line:

objCon = New SqlConnection()

Error message being:

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.

View 4 Replies

C# - Make A Control With Children Without Declaring The Template Tag?

Apr 4, 2011

I want to create a control just like a Panel.

I want my control to accept some controls as childs without typing the template name, just like the Panel, as shown here:

<asp:Panel runat="server">
My content
<div>Content</div>
</asp:Panel>

I have controls with content inside without telling what is the ITemplate.

I basically want to convert this

<my:MyControl runat="server">
<ContentTemplate>
My content
<div>Content</div>

[Code]....

The above works with <Content></Content> tags inside the control, but without it doesn't work. And the attribute isn't doing anything at all (I guess). What's missing?

View 6 Replies

SQL Server :: Declaring Variable In Stored Procedure?

Feb 16, 2011

I have this procedure

[Code]....

I don't know what variable should be put in where clause for tblVisitor.visitorID because there's a variable that was already passed by an output identity parameter by a different stored procedure. What will I put in the where clause for visitor id?

View 3 Replies

Web Forms :: Declaring Property Of Type Interface?

Jan 11, 2011

I have a Interface for CRUD operations.and some classes implemented it.I want to design a user control that have two buttons:insert and delete,to reuse this control over my forms.this class must have a instance of my interface to do insert and delete tasks (if I'm right).this is my interface:

[Code]...

my problem is,i can't declare a property of type ISchoolSystemRepository in user control,because i must pass T for interface.

View 1 Replies

Web Forms :: Basics About Declaring Static Class

May 7, 2015

What is the use of declaring the static class. I know that we cant create the object for the static class but i want to know that is the use of creating the class as static.

View 1 Replies

C# - Difference When Declaring A DataSource In Markup Compared To Code Behind

Jan 13, 2011

I have a legacy solution where all the DataSources are defined in the markup for all .aspx-pages. The problem I have with this is that the DataSource get instantiated several times since it is used in page, control... What I want is to have NInject to handle the instantiation of the DataSource so this doesn't happen. I have got that part to sort of work, but when the DataSource is defined in the code-behind instead of in the markup the Page property is not set on the DataSource, does anyone know why? A simple solution to this is to set the the Page property in a base class or something, but I do think that the property should be there and want to know why.

View 2 Replies

Directive Convention For Declaring Client-Side Includes?

Mar 10, 2011

I am loading .aspx and .ascx files as StreamReader.

I want each file to register it's javascript and stylesheet dependencies in some declaration like a <%@ ClientDependency path="~/Scripts/jquery-1.4.1.min.js" %>.

Is there an existing convention for doing such a thing? I don't need an implementation, but I don't want to create a new syntax if there is already a way to do it.

Also, what are the guidelines for custom <%@ blocks in ASP.NET?

View 3 Replies

How To Use Select Type In Dropdownlist In C# Without Declaring As A List Item

Apr 20, 2010

i have a dropdown list with values

America
Asia
Europe

I need to the display the ddl as Select Type and when i click the dropdownlist to see the values in it, it should display the three values, but i should not use Select Type as a list item and it should not be displayed in the list. It should only be used as a default text in ddl.

View 4 Replies

Web Forms :: Declaring The SqlConnection And SqlCommand Objects Without CodeBehind?

Sep 11, 2010

Declaring the SqlConnection and SqlCommand objects in a webform without CodeBehind I am trying to query data from a MS SQL server with a C# web form without "CodeBehind". I want to write the information to a table in the web form's body.

I am having trouble declaring the SqlConnection and SqlCommand objects that connect to the server.

How do you use "using System;", "using System.Data;", "using System.Data.SqlClient" inside the script element of an .ASPX file?

(code below)

[Code]....

View 5 Replies

Web Forms :: Designer File Not Declaring Controls Automatically?

Oct 26, 2010

I have been using .NET 2.0 and VS 2005 for web application project and lately i am noticing that .designer.aspx.cs does not declare all the controls 'automatically' which r there on .aspx...i add them manually and some of them get lost,like the additional 'div' controls which i have on pages inheritated from the master,everytime i reload it.. ..i fully understand that i am not suppose to manually change anything in designer.aspx.cs but what do i do with this issue? Is .net 2.0 ,VS 2005 are too obsolate and i absolutely need to get on .net 4.0,2010..

View 5 Replies

Working With Static Variables / Store The User Specific Information In Static Variables?

Mar 5, 2011

whats the exact use of static variables in overall programming in .net and for asp.net...

Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..

whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.

View 3 Replies

C# - Declaring Global Variable/class In Application Scope 3 Ways - Which One Is Best

Mar 3, 2010

I am looking for differences between those 3 ways of using static class in asp.net application scope.
Will all of these point to the same class?

Which one is preferable >object< defined declaratively inside global.asax or static class ?

examples:

<object runat="server" scope="application" class="classname" ID="objID"></object>

VS

public static class classname {}

VS

Application("a") = new classname();

View 1 Replies

DataSource Controls :: Declaring Today's Date In A Stored Procedure?

Apr 6, 2010

Can someone tell me the syntax to declare today's date in a stored procedure? I've searched around and can't come up with a clear answer.

I'm trying to declare today's date in the stored procedure and then compare it to a date in a database?

Is it as simple as the following or am i way off?

[Code]....

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved