|
|
| How to set focus of a control in C# |
Rather than call the
Focus() method programmatically, you can set a control that should always be
focused by setting the DefaultFocus property of the
<form> tag. <form DefaultFocus ="TextBox1" runat ="server">
You can override the default focus by calling the Focus() method in
your code. Another way to manage focus is using access keys. For example, if
you set the AccessKey property of a TextBox to A, pressing Alt+A focus will
switch to the TextBox. Labels can also get into the game, even though they
can’t accept focus. The trick is to set the Label.AssociatedControlID property
to specify a linked input control. That way, the label transfers focus to a
nearby control. For example, the following label gives focus to TextBox1 when
the keyboard combination Alt+2 is pressed:
<asp:Label AccessKey = "2" AssociatedControlID= "TextBox1" runat
="server" Text ="TextBox1:"/>
<asp:TextBox runat=server" ID="TextBox1"/>
Focusing and access keys are also supported in non-Microsoft browsers,
including Firefox.
|
|
| How to make Button Default in C#,Vb.net(asp.net) |
To designate a default button, you must set the HtmlForm.DefaultButton
property with the ID of the respective control, as shown here:
<form DefaultButton ="cmdSubmit" runat =server>
The default button must be a control that implements the IButtonControl
interface. The interface is implemented by the Button, LinkButton, and
ImageButton web controls but not by any of the HTML server
controls. In some cases, it makes sense to have more than one default button.
For example, you might create a web page with two groups of input controls.
Both groups may need a different default button. You can handle this by placing
the groups into separate panels. The Panel control also exposes the
DefaultButton property, which works when any input control it contains gets the
focus.
|
|
How to Create and Share Folder in C#.net Visual Studio 2008
|
|
try
{ // create a directory
Directory.CreateDirectory(@"C:\temp"); // Create a ManagementClass
object
ManagementClass managementClass = new
ManagementClass("Win32_Share");
ManagementBaseObject inp =
managementClass.GetMethodParameters("Create");
ManagementBaseObject outp; // Set the input parameters
inp["Description"] = "Share Folder";
inp["Name"] = "Share Folder";
inp["Path"] = @"C:\temp";
inp["Type"] = 0x0; // Disk Drive // Invoke the method on the
ManagementClass object
outp = managementClass.InvokeMethod("Create", inp, null); //
Check to see if the method invocation was successful
if((uint)(outp.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share folder.");
}
}
catch(Exception ex)
{
MessageBox.Show( ex.Message);
}
Note: Include following namespace also add Management .you also need
to explicitly add the System.Management library reference to your project.
using System.IO;
using System.Net;
using System.Management;
|
|
|