this article have thorough explaination of how to import unmanaged dll into .NET code and use it.
http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
using System.Runtime.InteropServices; // DllImport
public class Win32 {
[DllImport("User32.Dll")]
public static extern void SetWindowText(int h, String s);
}
Friday, September 30, 2005
Thursday, September 15, 2005
loop webcontrols in a page, and disable them all
all though we can loop Page.Controls, but not all of them are webcontrols( such as textbox, label, and dropdownlist). For example, the very first control in Page.Controls is the web form itself.
So what we really want to do is: loop every level of controls, see if they are the right type we are looking for, such as textbox, label, and dropdownlist, and disable them one by one.
the function needs be recursive, because there might be a usercontrol or panel in a page that contains web controls.
void DisableControls(ControlCollection controls)
{
foreach(Control c in controls)
{
try
{
TextBox tb= (TextBox)c;
tb.Enabled = false;
}
catch
{}
try
{
ListBox lb= (ListBox)c;
lb.Enabled = false;
}
catch
{}
try
{
RadioButtonList rb= (RadioButtonList)c;
rb.Enabled = false;
}
catch
{}
try
{
DropDownList ddl= (DropDownList)c;
ddl.Enabled = false;
}
catch
{}
try
{
CheckBox chk = (CheckBox)c;
chk.Enabled = false;
}
catch
{}
try
{
DisableControls(c.Controls);
}
catch{}
}
}
So what we really want to do is: loop every level of controls, see if they are the right type we are looking for, such as textbox, label, and dropdownlist, and disable them one by one.
the function needs be recursive, because there might be a usercontrol or panel in a page that contains web controls.
void DisableControls(ControlCollection controls)
{
foreach(Control c in controls)
{
try
{
TextBox tb= (TextBox)c;
tb.Enabled = false;
}
catch
{}
try
{
ListBox lb= (ListBox)c;
lb.Enabled = false;
}
catch
{}
try
{
RadioButtonList rb= (RadioButtonList)c;
rb.Enabled = false;
}
catch
{}
try
{
DropDownList ddl= (DropDownList)c;
ddl.Enabled = false;
}
catch
{}
try
{
CheckBox chk = (CheckBox)c;
chk.Enabled = false;
}
catch
{}
try
{
DisableControls(c.Controls);
}
catch{}
}
}
add a blank entry to the databind dropdownlist
first of all, keep in mind that adding entry before databinding won't work at all. we should always add the blank entry after binding:
dpQuestion.DataSource = GetQuestions();
dpQuestion.DataTextField = "QSTN_DESC";
dpQuestion.DataValueField = "QSTN_ID";
dpQuestion.DataBind();
//add a blank entry at top
dpQuestion.Items.Insert(0,new ListItem("",""));
dpQuestion.DataTextField = "QSTN_DESC";
dpQuestion.DataValueField = "QSTN_ID";
dpQuestion.DataBind();
//add a blank entry at top
dpQuestion.Items.Insert(0,new ListItem("",""));
Monday, September 12, 2005
retain value of password filed when postback
use this code:
If(IsPostBack)
{
this.txtFedTaxID.Attributes["value"] = txtFedTaxID.Text;
this.txtFedTaxID2.Attributes["value"] = txtFedTaxID2.Text;
}
"txtFedTaxID.Text = txtFedTaxID.Text" won't work for the password field.
If(IsPostBack)
{
this.txtFedTaxID.Attributes["value"] = txtFedTaxID.Text;
this.txtFedTaxID2.Attributes["value"] = txtFedTaxID2.Text;
}
"txtFedTaxID.Text = txtFedTaxID.Text" won't work for the password field.
Subscribe to:
Posts (Atom)