1 | What is ASP.NET? |
2 | Why does my ASP.NET file have multiple <form> tag with runat=server? |
3 | How to find out what version of ASP.NET I am using on my machine? |
4 | Is it possible to pass a querystring from an .asp page to aspx page? |
5 | How to comment out ASP.NET Tags? |
6 | What is a ViewState? |
7 | Where can I get the details on Migration of existing projects using various technologies to ASP.NET? |
8 | What is the equivalent of date() and time() in ASP.NET? |
9 | How to prevent a button from validating it's form? |
10 | How to get the IP address of the host accessing my site? |
11 | How to access the Parameters passed in via the URL? |
12 | How to Set Focus to Web Form Controls By Using Client-Side Script? |
13 | How to display a Wait page while a query is running? |
14 | How to implement Form based Authentication in ASP.NET application? |
15 | How to catch the 404 error in my web application and provide more useful information? |
16 | Is there a method similar to Response.Redirect that will send variables to the destination page other than using a query string or the post method? |
17 | What are the differences between HTML versus Server Control? |
18 | How can I change the action of a form through code? |
19 | Is there any control that allows user to select a time from a clock - in other words is there a clock control? |
20 | How to Compare time? |
21 | How To work with TimeSpan Class? |
22 | Where can I get information on Cookies in ASP.NET? |
23 | Does ASP.Net still recognize the global.asa file? |
24 | How should I destroy my objects in ASP.Net? |
25 | Are there resources online with tips on ASP to ASP.Net conversions? |
26 | How do I publish my ASP.NET application to my ISP's web server? |
27 | Why do i get error message "Could not load type" whenever I browse to my ASP.NET web site? |
28 | Will the WebMatrix SqlDataSourceControl work with a MySQL connection? |
29 | Can I combine classic ASP and ASP.NET pages? |
30 | What is the difference between src and Code-Behind? |
31 | How can I get the value of input box with type hidden in code-behind? |
32 | I have created a .NET user control page (.ascx) but I cannot compile and run it. |
33 | What is a .resx file? |
34 | Is it possible to use a style sheet class directly on a control instead of using inline or page-level formatting ? |
35 | Can I recieve both HTML markup for page and code in the ASP.NET web page's source code portion in the Web browser? |
36 | Why can't I put <%@ Page Language="C " %> where at the top of an ASPX file and write my server-side scripts in C ? |
37 | ASP pages that worked pefectly on Windows 2000 Server and IIS 5.0 do not work on Windows 2003 Server with IIS 6.0. ASP.NET pages work fine. Why? |
38 | Why do I get error message "Error creating assembly manifest: Error reading key file 'key.snk' -- The system cannot find the file specified"? |
39 | How to get URL without querystring? |
40 | What is the best way to output only time and not Date? |
41 | Do I have to compile code if I am changing the content of my aspx.cs file? |
42 | How to grab the referring URL? |
43 | My ASP code gives an error "Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed" when changed to .aspx? |
44 | How can I save images ? |
45 | How can I logout when using FormsAuthentication? |
46 | Why do I get a blank page when I use Server.Transfer("page1.htm") to transfer to a different page? |
47 | How to detect the User's culture? |
48 | What is the difference between CurrentCulture property and the CurrentUICulture property? |
49 | Can I read the hard disk serial # of the client computer using ASP.NET? |
50 | What is xxx(src As Object, e As EventArgs)? |
51 | What is the difference between Absolute vs Relative URLs? |
52 | What is the difference between URL and URI? |
53 | How to convert milliseconds into time? |
54 | How to include multiple vb/cs files in the source? |
55 | How to convert a string to Proper Case? |
56 | How can I ensure that application-level variables are not updated by more than one user simultaneously? |
58 | How to validate that a string is a valid date? |
59 | Are namespaces and Class names Case Sensitive? |
60 | How to convert string to a DateTime and compare it with another DateTime? |
61 | How to get the url of page dynamically? |
62 | How to convert user input in dMy format to Mdy? |
64 | How to hide or show Controls in server side code? |
65 | How to check if the user is using a secure or non secure connection? |
66 | Is it possible to write code in many languages in one ASP.NET project? |
67 | What is the difference between Response.Redirect() and Server.Transfer(). |
68 | How to get the hostname or IP address of the server? |
69 | What is the meaning of validateRequest=true in .net framework1.1? |
70 | What is the different between <%# %> and <%= %>? |
71 | What permissions do ASP.NET applications posses by default? |
72 | How can I specify the relative path for a file? |
74 | How to change the Page Title dynamically? |
75 | Why do I get the error message "Object must implement IConvertible". How can I resolve it? |
76 | Why is default.aspx page not opened if i specify http://localhost. I am able to view this page if i hardcode it as http://localhost/default.aspx? |
77 | Can ASP.NET work on an NT server? |
78 | Is it possible to migrate Visual InterDev Design-Time Controls to ASP.NET? |
79 | How to automatically get the latest version of all the asp.net solution items from Source Safe when opening the solution? |
80 | How to convert the datetime into a string for use in the SQL ' statement? |
81 | How to make VS.Net use FlowLayout as the default layout rather than the GridLayout? |
82 | Can I use a DataReader to update/insert/delete a record? |
83 | What is the difference between Server.Transfer and Server.Execute? |
84 | How to create a login screen in ASP.NET? |
85 | How to format a Telphone number in the xxx-xxx-xxxx format? |
86 | Can two different programming languages be mixed in a single ASPX file? |
87 | Can I use custom .NET data types in a Web form? |
88 | How can I have a particular Web page in an ASP.NET application which displays its own error page. |
2.1 What is ASP.NET? | top |
ASP.NET is a programming framework built on the common language For more details refer |
2.2 Why does my ASP.NET file have multiple <form> tag with runat=server? | top |
This means that ASP.Net is not properly registered with IIS. |
use the command: aspnet_regiis.exe -u ---> to uninstall current asp.net version. |
use the command: aspnet_regiis.exe -i ---> to install current asp.net version. |
For Windows Server 2003, you must use aspnet_regiis -i -enable (if you install VS.NET or the framework without IIS installed, and |
2.3 How to find out what version of ASP.NET I am using on my machine? | top |
VB.NET |
Response.Write(System.Environment.Version.ToString() ) |
C# |
Response.Write(System.Environment.Version.ToString() ); |
2.4 Is it possible to pass a querystring from an .asp page to aspx page? | top |
Yes you can pass querystring from .asp to ASP.NET page .asp |
<%response.redirect "webform1.aspx?id=11"%> |
.aspx |
Response.Write (Request("id").ToString ()) |
C# |
Response.Write (Request["id"].ToString ()); |
2.5 How to comment out ASP.NET Tags? | top |
<%--<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 48px" runat="server">Label</asp:Label>--%> |
2.6 What is a ViewState? | top |
In classic ASP, when a form is submitted the form values are cleared. In ASP .NET, when the form is submitted the form reappears in the |
<input type="hidden" name="__VIEWSTATE" value="dDwyNTA3OTU0NDM7Oz7t5TntzkOUeB0QVV6FT2hvQwtpPw==" /> |
If you want to NOT maintain the ViewState, include the directive |
2.7 Where can I get the details on Migration of existing projects using various technologies to ASP.NET? | top |
Microsoft has designed Migration Assistants to help us convert
Refer Migrating to ASP.Net |
2.8 What is the equivalent of date() and time() in ASP.NET? | top |
VB.NET |
System.DateTime.Now.ToShortDateString() |
System.DateTime.Now.ToShortTimeString() |
C# |
System.DateTime.Now.ToShortDateString(); |
System.DateTime.Now.ToShortTimeString(); |
2.9 How to prevent a button from validating it's form? | top |
Set the CauseValidation property of the button control to False |
2.10 How to get the IP address of the host accessing my site? | top |
VB.NET |
Response.Write (Request.UserHostAddress.ToString ()) |
C# |
Response.Write (Request.UserHostAddress.ToString ()); |
2.11 How to access the Parameters passed in via the URL? | top |
Call the Request.QueryStringmethod passing in the key. The |
Request.QueryString("id") |
C# |
Request.QueryString["id"]; |
2.12 How to Set Focus to Web Form Controls By Using Client-Side Script? | top |
<script language="javascript"> |
function SetFocus() |
{ |
// W3C approved DOM code that will work in all modern browsers |
if (document.getElementById) |
document.getElementById('txt2').focus(); |
else |
// To support older versions of IE: |
if (document.all) |
document.all("txt2").focus(); |
return false; |
} |
</script> |
<body MS_POSITIONING="GridLayout" onload="SetFocus()"> |
<form id="Form1" method="post" runat="server"> |
Enter 1: |
<asp:TextBox ID="txt1" Runat="server" Width="50" /> |
<br> |
Enter 2: |
<asp:TextBox ID="txt2" Runat="server" Width="50" /> |
<br> |
<asp:Button id="Button1" runat="server" Text="Button1"></asp:Button> |
</form> |
</body> |
Refer |
2.13 How to display a Wait page while a query is running? | top |
Refer |
2.14 How to implement Form based Authentication in ASP.NET application? | top |
For |
2.15 How to catch the 404 error in my web application and provide more useful information? | top |
In the global.asax Application_error Event write the following code VB.NET |
Dim ex As Exception = Server.GetLastError().GetBaseException() |
If TypeOf ex Is System.IO.FileNotFoundException Then |
'your code |
'Response.Redirect("err404.aspx") |
Else |
'your code |
End If |
C# |
Exception ex = Server.GetLastError().GetBaseException(); |
if (ex.GetType() == typeof(System.IO.FileNotFoundException)) |
{ |
//your code |
Response.Redirect ("err404.aspx"); |
} |
else |
{ |
//your code |
} |
2.16 Is there a method similar to Response.Redirect that will send variables to the destination page other than using a query string or the post method? | top |
Server.Transfer preserves the current page context, so that in the Another way to pass values is to use something like a LinkButton. It Refer to |
2.17 What are the differences between HTML versus Server Control? | top |
Refer |
2.18 How can I change the action of a form through code? | top |
You can't change it. The action attribute is owned by ASP.NET. Handle For work around refer to Paul Wilson's |
2.19 Is there any control that allows user to select a time from a clock - in other words is there a clock control? | top |
Peter Blum has developed some controls. Check out |
2.20 How to Compare time? | top |
VB.NET |
Dim t1 As String = DateTime.Parse("3:30 PM").ToString("t") |
Dim t2 As String = DateTime.Now.ToString("t") |
If DateTime.Compare(DateTime.Parse(t1), DateTime.Parse(t2)) < 0 Then |
Response.Write(t1.ToString() & " is < than " & t2.ToString()) |
Else |
Response.Write(t1.ToString() & " is > than " & t2.ToString()) |
End If |
C# |
string t1 = DateTime.Parse("3:30 PM").ToString("t"); |
string t2 = DateTime.Now.ToString("t"); |
if (DateTime.Compare(DateTime.Parse (t1), DateTime.Parse (t2)) < 0 ) |
{ |
Response.Write(t1.ToString() + " is < than " + t2.ToString()); |
} |
else |
{ |
Response.Write(t1.ToString() + " is > than " + t2.ToString()); |
} |
2.21 How To work with TimeSpan Class? | top |
VB.NET |
Dim adate As DateTime = DateTime.Parse("06/24/2003") |
Dim bdate As DateTime = DateTime.Parse("06/28/2003") |
Dim ts As New TimeSpan(bdate.Ticks - adate.Ticks) |
Response.Write(ts.TotalDays & "<br>") |
Response.Write(ts.TotalHours & ":" & ts.TotalMinutes & ":" & ts.TotalSeconds & ":" & ts.TotalMilliseconds) |
C# |
DateTime adate = DateTime.Parse("06/24/2003"); |
DateTime bdate = DateTime.Parse("06/28/2003"); |
TimeSpan ts = new TimeSpan (bdate.Ticks - adate.Ticks); |
Response.Write(ts.TotalDays.ToString () + "<br>"); |
Response.Write(ts.TotalHours.ToString() + ":" + ts.TotalMinutes.ToString() + ":" + ts.TotalSeconds.ToString() + ":" + ts.TotalMilliseconds.ToString() ); |
2.22 Where can I get information on Cookies in ASP.NET? | top |
Refer Mike Pope's article |
2.23 Does ASP.Net still recognize the global.asa file? | top |
ASP.Net does not recognize the standard ASP global.asa file. Instead |
2.24 How should I destroy my objects in ASP.Net? | top |
ASP.Net actually has very solid internal garbage collection. So this |
2.25 Are there resources online with tips on ASP to ASP.Net conversions? | top |
Microsoft has deisnged The ASP to ASP.NET Migration Assistant help us The following Code Migration Assistants are discussed in the link
Refer Migrating to ASP.Net Also refer:
|
2.26 How do I publish my ASP.NET application to my ISP's web server? | top |
Your ISP must first create an IIS application and apply the Front You can also FTP your files to your ISP web server. But you must know |
2.27 Why do i get error message "Could not load type" whenever I browse to my ASP.NET web site? | top |
Your code-behind files for either your .aspx or the global.aspx page For more details refer |
2.28 Will the WebMatrix SqlDataSourceControl work with a MySQL connection? | top |
SqlDataSourceControl lets you connect and work with MS SQL DB, while |
2.29 Can I combine classic ASP and ASP.NET pages? | top |
No. |
2.30 What is the difference between src and Code-Behind? | top |
Src attribute means you deploy the source code files and everything CodeBehind attribute doesn't really "do" anything, its just a helper |
2.31 How can I get the value of input box with type hidden in code-behind? | top |
You can set the runat= server for the hidden control and you can use |
2.32 I have created a .NET user control page (.ascx) but I cannot compile and run it. | top |
User control (ascx) can't be run on it own, but you can drag it onto |
2.33 What is a .resx file? | top |
The .resx resource file format consists of XML entries, which specify |
2.34 Is it possible to use a style sheet class directly on a control instead of using inline or page-level formatting ? | top |
Every WebControl derived control has a CssClass property which allows |
2.35 Can I recieve both HTML markup for page and code in the ASP.NET web page's source code portion in the Web browser? | top |
No. The Web browser recieves only HTML markup. |
2.36 Why can't I put <%@ Page Language="C " %> where at the top of an ASPX file and write my server-side scripts in C ? | top |
The parsers ASP.NET uses to extract code from ASPX files understand |
2.37 ASP pages that worked pefectly on Windows 2000 Server and IIS 5.0 do not work on Windows 2003 Server with IIS 6.0. ASP.NET pages work fine. Why? | top |
Start -> Settings -> Control Panel -> Administrative Tools -> and |
2.38 Why do I get error message "Error creating assembly manifest: Error reading key file 'key.snk' -- The system cannot find the file specified"? | top |
Check the location of the key.snk file relative to the assembly file. |
<Assembly: AssemblyKeyFileAttribute("Drive:\key.snk")> |
2.39 How to get URL without querystring? | top |
VB.NET |
Dim stringUri As String = "http://www.syncfusion.com/?id=1&auid=16" |
Dim weburi As Uri = New Uri(stringUri) |
Dim query As String = weburi.Query |
Dim weburl As String = stringUri.Substring(0, stringUri.Length - query.Length) |
Response.Write(weburl) |
C# |
string stringUri = "http://www.syncfusion.com/?id=1&auid=16"; |
Uri weburi = new Uri(stringUri); |
string query = weburi.Query; |
string weburl = stringUri.Substring(0, stringUri.Length - query.Length); |
Response.Write (weburl); |
2.40 What is the best way to output only time and not Date? | top |
Use DateTime as follows VB.NET |
Response.Write(DateTime.Now.ToString("hh:mm:ss")) |
C# |
Response.Write(DateTime.Now.ToString("hh:mm:ss")); |
2.41 Do I have to compile code if I am changing the content of my aspx.cs file? | top |
Yes if you have used Codebehind="my.aspx.cs". |
2.42 How to grab the referring URL? | top |
VB.NET |
Response.Write ( Request.UrlReferrer.ToString()) |
C# |
Response.Write ( Request.UrlReferrer.ToString()); |
2.43 My ASP code gives an error "Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed" when changed to .aspx? | top |
Use a <script runat=server> block instead of the <% %> syntax to |
2.44 How can I save images ? | top |
You need a stream to read the response, |
2.45 How can I logout when using FormsAuthentication? | top |
VB.NET |
FormsAuthentication.SignOut() |
C# |
FormsAuthentication.SignOut(); |
2.46 Why do I get a blank page when I use Server.Transfer("page1.htm") to transfer to a different page? | top |
Server.Transfer only works with .aspx pages |
2.47 How to detect the User's culture? | top |
VB.NET |
Dim sLang As String |
sLang = Request.UserLanguages(0) |
Response.Write(sLang) |
C# |
string sLang ; |
sLang = Request.UserLanguages[0]; |
Response.Write (sLang); |
2.48 What is the difference between CurrentCulture property and the CurrentUICulture property? | top |
|
2.49 Can I read the hard disk serial # of the client computer using ASP.NET? | top |
No. Such information is not passed to the server with a http request. |
2.50 What is xxx(src As Object, e As EventArgs)? | top |
xxx is an event handler |
2.51 What is the difference between Absolute vs Relative URLs? | top |
Absolute /Fully Qualified URLs:
Relative URLs:
|
2.52 What is the difference between URL and URI? | top |
A URL is the address of some resource on the Web, which means that A URI is just a unique string that uniquely identifies something, URI is the more generic term, and a URL is a particular type of URI |
2.53 How to convert milliseconds into time? | top |
VB.NET |
dim ts as TimeSpan = TimeSpan.FromMilliseconds(10000) |
Response.Write (ts.ToString () ) |
C# |
TimeSpan ts = TimeSpan.FromMilliseconds(10000); |
Response.Write (ts.ToString () ); |
2.54 How to include multiple vb/cs files in the source? | top |
You can do this using assembly directives. |
<%@ assembly src="test1.vb" %> |
<%@ assembly src="test2.vb" %> |
or |
<%@ assembly src="test1.cs" %> |
<%@ assembly src="test2.cs" %> |
However, note that each source file will be compiled individually |
2.55 How to convert a string to Proper Case? | top |
Use the namespace System.Globalization |
Dim myString As String = "syncFusion deVeloPer sUppOrt" |
' Creates a TextInfo based on the "en-US" culture. |
Dim TI As TextInfo = New CultureInfo("en-US", False).TextInfo |
Response.Write(TI.ToTitleCase(myString)) |
C# |
string myString = "syncFusion deVeloPer sUppOrt"; |
// Creates a TextInfo based on the "en-US" culture. |
TextInfo TI = new CultureInfo("en-US",false).TextInfo; |
Response.Write (TI.ToTitleCase( myString )); |
For more details refer |
2.56 How can I ensure that application-level variables are not updated by more than one user simultaneously? | top |
Use the HttpApplicationState's Lock and UnLock methods. For more details refer : |
2.57 Why do I get the error message "System.InvalidOperationException: It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a ...."? | top |
You can't use MsgBox or MessageBox.Show in ASP.NET WebForm. You maybe |
Response.Write("<script>alert('Hello');</script>") |
C# |
Response.Write("<script>alert('Hello');</script>") ; |
2.58 How to validate that a string is a valid date? | top |
VB.NET |
Dim blnValid As Boolean = False |
Try |
DateTime.Parse(MyString) |
blnValid = True |
Catch |
blnValid = False |
End Try |
C# |
bool blnValid=false; |
try |
{ |
DateTime.Parse(MyString); |
blnValid=true; |
} |
catch |
{ |
blnValid=false; |
} |
2.59 Are namespaces and Class names Case Sensitive? | top |
Namespaces and Class names are case Sensitive. Namespaces imported |
2.60 How to convert string to a DateTime and compare it with another DateTime? | top |
VB.NET |
Dim blntimeIsOk As Boolean = DateTime.Parse("15:00") < DateTime.Parse("08:00") |
Response.Write(blntimeIsOk) |
C# |
bool blntimeIsOk = (DateTime.Parse("15:00") < DateTime.Parse("08:00")); |
Response.Write (blntimeIsOk); |
2.61 How to get the url of page dynamically? | top |
Use Request.Url property |
2.62 How to convert user input in dMy format to Mdy? | top |
VB.NET |
Dim dt As DateTime = DateTime.ParseExact("0299", New String() {"My", "M/y"}, Nothing, System.Globalization.DateTimeStyles.None) |
C# |
DateTime dt = DateTime.ParseExact("0299", new string[] {"My","M/y"}, null,System.Globalization.DateTimeStyles.None); |
For more details refer |
2.63 When the User is prompted a File Download dialogbox, if the user selects "Save" then the "Save as" dialog box is displayed. Is there any way for me to retrieve the filename and directory path specified by the user on the File Download dialog box? | top |
Clients do not report information back about where the user selects |
2.64 How to hide or show Controls in server side code? | top |
In any appropriate event write |
TextBox1.Visible =not TextBox1.Visible |
C# |
TextBox1.Visible =!TextBox1.Visible ; |
2.65 How to check if the user is using a secure or non secure connection? | top |
The Request Object defines a Property called |
2.66 Is it possible to write code in many languages in one ASP.NET project? | top |
You cannot write the code-behind files in different languages in the |
2.67 What is the difference between Response.Redirect() and Server.Transfer(). | top |
Response.Redirect
Server.Transfer
Sometimes for performance reasons, the server method is more desirable
|
2.68 How to get the hostname or IP address of the server? | top |
You can use either of these:
The first one should return the name of the machine, the second returns the local ip address. Note that name of the machine could be different than host, since your site could be using host headers |
2.69 What is the meaning of validateRequest=true in .net framework1.1? | top |
The value of validateRequest is set to 'true' by default, which means |
2.70 What is the different between <%# %> and <%= %>? | top |
The <%# %> is used for databinding where as <%= %> is used to output |
2.71 What permissions do ASP.NET applications posses by default? | top |
By default ASP.NET Web applications run as ASP.NET user. This user |
2.72 How can I specify the relative path for a file? | top |
Suppose you have following file hierarchy: |
default.aspx |
Admin/login.aspx |
Misc/testpage.aspx |
|
2.73 How can I specify the "upload a file" input textbox in a form to be read only so that the user can click on the browse button and pick a file but they cannot type anything into the textbox next to the browse button. | top |
<input id="File1" type="file" contenteditable=false /> |
2.74 How to change the Page Title dynamically? | top |
<TITLE id="Title1" runat =server ></TITLE> |
VB.NET |
'Declare |
Protected WithEvents Title1 As System.Web.UI.HtmlControls.HtmlGenericControl |
'In Page_Load |
Title1.InnerText ="Page 1" |
C# |
//Declare |
protected System.Web.UI.HtmlControls.HtmlGenericControl Title1 ; |
//In Page_Load |
Title1.InnerText ="Page 1" ; |
2.75 Why do I get the error message "Object must implement IConvertible". How can I resolve it? | top |
The common cause for this error is specifying a control as a VB.NET |
Dim nameParameter As SqlParameter = command.Parameters.Add("@name", SqlDbType.NVarChar, 50) |
nameParameter.Value = txtName |
C# |
SqlParameter nameParameter = command.Parameters.Add("@name", SqlDbType.NVarChar, 50); |
nameParameter.Value = txtName ; |
To resolve it, specify the control's Text property instead of the VB.NET |
nameParameter.Value = txtName.Text |
C# |
nameParameter.Value =txtName.Text; |
2.76 Why is default.aspx page not opened if i specify http://localhost. I am able to view this page if i hardcode it as http://localhost/default.aspx? | top |
If some other default page comes higher in the list, adjust the |
2.77 Can ASP.NET work on an NT server? | top |
No. For more details refer |
2.78 Is it possible to migrate Visual InterDev Design-Time Controls to ASP.NET? | top |
Refer |
2.79 How to automatically get the latest version of all the asp.net solution items from Source Safe when opening the solution? | top |
In VS.NET you can go to Tools > Options > Source Control > General |
2.80 How to convert the datetime into a string for use in the SQL ' statement? | top |
<asp:label id="Label2" runat="server">Select a culture: </asp:label> |
<asp:dropdownlist id="ddlCulture" runat="server" autopostback="True"></asp:dropdownlist> |
<P></P> |
<asp:label id="Label3" runat="server">DateTime in Selected Culture</asp:label> |
<asp:textbox id="TextBox1" runat="server"></asp:textbox> |
<p> |
<asp:label id="Label1" runat="server"></asp:label> |
VB.NET |
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
'Put user code to initialize the page here |
If Not Page.IsPostBack Then |
Dim cInfo As CultureInfo |
For Each cInfo In CultureInfo.GetCultures(CultureTypes.SpecificCultures) |
ddlCulture.Items.Add(cInfo.Name) |
Next |
End If |
End Sub |
Private Sub ddlCulture_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCulture.SelectedIndexChanged |
' Get a CultureInfo object based on culture selection in dropdownlist |
Dim cInfo As CultureInfo = New CultureInfo(ddlCulture.SelectedItem.Text) |
' Get a CultureInfo object based on Invariant culture |
Dim cInfoNeutral As CultureInfo = New CultureInfo("") |
' Display the datetime based on the formatting of the selected culture |
TextBox1.Text = Convert.ToString(Now, cInfo.DateTimeFormat) |
' Create a DateTime variable to hold the Invariant time |
Dim dt As DateTime |
dt = Convert.ToDateTime(TextBox1.Text, cInfo.DateTimeFormat) |
'Convert the datetime into a string for use in the SQL statement |
Label1.Text = "... WHERE ([Date] < '" & _ |
Convert.ToString(dt, cInfoNeutral.DateTimeFormat) & "')" |
End Sub |
C# |
private void Page_Load(object sender, System.EventArgs e) |
{ |
// Put user code to initialize the page here |
if (!Page.IsPostBack ) |
{ |
foreach(CultureInfo cInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) |
{ |
ddlCulture.Items.Add(cInfo.Name); |
} |
} |
} |
private void ddlCulture_SelectedIndexChanged(object sender, System.EventArgs e) |
{ |
// Get a CultureInfo object based on culture selection in dropdownlist |
CultureInfo cInfo = new CultureInfo(ddlCulture.SelectedItem.Text); |
// Get a CultureInfo object based on Invariant culture |
CultureInfo cInfoNeutral = new CultureInfo(""); |
// Display the datetime based on the formatting of the selected culture |
TextBox1.Text = Convert.ToString(DateTime.Now , cInfo.DateTimeFormat); |
// Create a DateTime variable to hold the Invariant time |
DateTime dt ; |
dt = Convert.ToDateTime(TextBox1.Text, cInfo.DateTimeFormat); |
//Convert the datetime into a string for use in the SQL statement |
Label1.Text = "... WHERE ([Date] < '" + Convert.ToString(dt, cInfoNeutral.DateTimeFormat) + "')"; |
} |
2.81 How to make VS.Net use FlowLayout as the default layout rather than the GridLayout? | top |
For VB.NET, go to path C:\Program Files\Microsoft Visual Studio |
<body MS_POSITIONING="[!output DEFAULT_HTML_LAYOUT]"> |
to |
For C#, go to path C:\Program Files\Microsoft Visual Studio .NET |
<body MS_POSITIONING="[!output DEFAULT_HTML_LAYOUT]"> |
to |
Note:Before changing any templates it's a good idea to make backup
|
2.82 Can I use a DataReader to update/insert/delete a record? | top |
No. DataReader provides a means of reading a forward-only stream of |
2.83 What is the difference between Server.Transfer and Server.Execute? | top |
|
2.84 How to create a login screen in ASP.NET? | top |
Here is a sample login screen: |
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1"> |
<TR> |
<TD> |
<asp:Label id="Label1" runat="server">User Name</asp:Label></TD> |
<TD> |
<asp:TextBox id="txtUserName" runat="server"></asp:TextBox></TD> |
<TD> |
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtUserName"></asp:RequiredFieldValidator></TD> |
</TR> |
<TR> |
<TD> |
<asp:Label id="Label2" runat="server">Password</asp:Label></TD> |
<TD> |
<asp:TextBox id="txtPassword" runat="server"></asp:TextBox></TD> |
<TD> |
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></TD> |
</TR> |
<TR> |
<TD></TD> |
<TD> |
<asp:Button id="btnLogin" runat="server" Text="Login"></asp:Button></TD> |
<TD></TD> |
</TR> |
</TABLE> |
VB.NET |
Dim myconnection As SqlConnection |
Dim mycmd As SqlCommand |
Dim strSql As String |
Dim myReader As SqlDataReader |
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click |
myconnection = New SqlConnection("Server=localhost;uid=sa;password=;database=northwind;") |
strSql = "Select * from usertbl where username=" & "'" & txtUserName.Text & "'" & " and userpassword=" & "'" & txtPassword.Text & "'" |
mycmd = New SqlCommand(strSql, myconnection) |
myconnection.Open() |
myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection) |
If myReader.Read() Then |
Response.Write("Welcome") |
Else |
Response.Write("Access Denied") |
End If |
End Sub |
C# |
SqlConnection myconnection ; |
SqlCommand mycmd ; |
string strSql ; |
SqlDataReader myReader ; |
private void btnLogin_Click(object sender, System.EventArgs e) |
{ |
myconnection = new SqlConnection("Server=localhost;uid=sa;password=;database=northwind;"); |
strSql = "Select * from usertbl where username=" + "'" + txtUserName.Text + "'" + " and userpassword=" + "'" + txtPassword.Text + "'"; |
mycmd = new SqlCommand(strSql, myconnection); |
myconnection.Open(); |
myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection); |
if (myReader.Read() ) |
{ |
Response.Write("Welcome"); |
} |
else |
{ |
Response.Write("Access Denied"); |
} |
} |
2.85 How to format a Telphone number in the xxx-xxx-xxxx format? | top |
VB.NET |
Dim Telno As Double = Double.Parse(ds.Tables(0).Rows(0)("TelNo").ToString()) |
Response.Write(Telno.ToString("###-###-####")) |
C# |
double Telno= double.Parse(ds.Tables[0].Rows[0]["TelNo"].ToString()); |
Response.Write(Telno.ToString("###-###-####")); |
2.86 Can two different programming languages be mixed in a single ASPX file? | top |
No. ASP.NET uses parsers to strip the code from ASPX files and copy |
2.87 Can I use custom .NET data types in a Web form? | top |
Yes. Place the DLL containing the type in the application root's bin |
2.88 How can I have a particular Web page in an ASP.NET application which displays its own error page. | top |
This can be done by setting the ErroPage attribute of Page Directive |
<%@Page Language="C#" ErrorPage="specificerropage.htm"%> |
In web.config |
<customErrors mode="On" /> |
Comments