OnKeyPress(KeyPressEventArgs e)

  • Thread starter Thread starter Mohamed Oubouchil
  • Start date Start date
M

Mohamed Oubouchil

Hi All,
Thanks Daniel for your help.
Now i'm facing one problem in my control application ASP.NET with C#
i'm using the code below:
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public class MyText : System.Web.UI.WebControls.TextBox
{
private const char VK_BACK =(char)Keys.Back;
private const char VK_RETURN =(char)Keys.Return;
private const char VK_LEFT =(char)Keys.Left;
private const char VK_RIGHT =(char)Keys.Right;
private const char VK_DOWN =(char)Keys.Down;
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.KeyChar!=VK_BACK
e.Handled = true;
}
}

But i have more error like this :
The type or namespace name 'Keys' could not be found (are you missing
a using directive or an assembly reference?)

Thanks advanced for your help

Mohamed oubouchil
 
No problem Mohamed. What did they reply in the

* microsoft.public.dotnet.framework.aspnet.webcontrols *

newsgroup?

Cheers
Daniel
 
Hello Luis,

I tryed this way but i get this error:(571):
'MyCtrls.MyTextBox.OnKeyPress(System.Windows.Forms.KeyPressEventArgs)':
no suitable method found to override.
For more détails, my application is building a new webcontrol based
System.Web.UI.WebControls.TextBox then i herited all function from
webcontrol TextBox, but i need to modify some function like
OnKeyPress.If i add using System.Windows.Forms; it's confuse with using
System.Web.UI.WebControls;

Thanks and best regards,

Mohamed Oubouchil
 
Hello Mohamed,

i think i should have explained what i meant better. ok, here it goes:

what i said was that the enumeration you're trying to use (Keys) was defined
in System.Windows.Forms. So, if you want to use it, you'll have to include
it or use the complete path to it.

however, if you know the codes of the keys, you don't need to use those values
as this msdn sample demonstrates:

http://msdn.microsoft.com/library/d...wsformskeypresseventargsclasskeychartopic.asp

one more thing: i've realized that you're developing a web control. is it
really necessary to process the keys on the server side?

----
Regards,
Luis Abreu
mail to: labreu_at_gmail.com
http://weblogs.pontonetpt.com/luisabreu
http://weblogs.pontonetpt.com
http://www.pontonetpt.com
 
Hello Luis,

this is my situation:
From Visual Studio.net i open a new project the i select Project Type is
C# and Templates Web Controls Library, then i use this code below :
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Windows.Forms;
namespace MyTextBox
{
/// <summary>
/// Summary description for MyTextBox.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:MyTextBox runat=server></{0}:MyTextBox>")]
public class MyTextBox : System.Web.UI.WebControls.TextBox
{
private string text;

[Bindable(true),
Category("Appearance"),
DefaultValue("")]
private const char VK_BACK =(char)Keys.Back;
private const char VK_RETURN =(char)Keys.Return;
private const char VK_LEFT =(char)Keys.Left;
private const char VK_RIGHT =(char)Keys.Right;
private const char VK_DOWN =(char)Keys.Down;
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.KeyChar!=VK_BACK;
e.Handled = true;
}
public new string Text
{
get
{
return text;
}

set
{
text = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}

But i have always the same last error on function OnKeyPress
 
Back
Top