PDA

View Full Version : Textbox - onFocus


many_tentacles
12-11-2008, 02:59 PM
Hi

I have this code which works perfectly... except for the fact I need it to work in VB rather than C#.

Any ideas... please.

<%@ Page Language="C#" %>
<script runat="server">

protected void Page_Load(object sender,EventArgs e)
{

txtName.Attributes.Add("onfocus","clearText()");
txtName.Attributes.Add("onblur","resetText()");
}



</script>
<html>
<head>
<title>Alterting control focus on the server side</title>
<script language="JavaScript">
<!--

function clearText() {
if(document.form1.txtName.value == "(enter something here)")
document.form1.txtName.value = ""

}

function resetText() {
if(document.form1.txtName.value == "")
document.form1.txtName.value = "(enter something here)"
}
// -->
</script>
</head>
<body>
<form runat="server" id="form1">

<asp:Textbox id="txtName" text="(enter something here)" runat="server"/>


</form>


</body>
</html>

pigpen
12-13-2008, 08:18 PM
Any reason why you have to have it in VB?

YOu can run both VB and C# scripts in your website project file.

If you have to change the C# to VB, some try some converter.

Here I googled "VB to C#" and this was the first thing that popped up.

http://www.developerfusion.com/tools/convert/csharp-to-vb/

hivelocitydd
12-19-2008, 05:13 AM
protected void Page_Load(object sender,EventArgs e)
{ us.Add("onfocus","clearText()");
txtName.Attributes.Add("onblur","resetText()");
}

Only this part you need to convert.instead of using this u can call the javascript functions on the textbox leave event

Freon22
12-19-2008, 01:41 PM
I think he want the C# code in VB.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
txtName.Attributes.Add("onfocus", "clearText()")
txtName.Attributes.Add("onblur", "resetText()")
End Sub

Another thing from what I have read you can run vb and c# in the same web project. But keep in mind that you can only have one code type in the App_Code folder. But MS does have an easy work around.

Multiple Programming Languages in the App_Code Folder
Because the source code in the App_Code folder is compiled into a single assembly, all the files in the App_Code folder must be in the same programming language. For example, the App_Code folder cannot include source code in both Visual Basic and C#.

However, you can configure your Web application to treat subfolders of the App_Code folder as separate compilable units. Each folder can then contain source code in a different programming language. The configuration is specified by creating a codeSubDirectories element in the compilation element of the Web.config file and adding a reference to the subfolder. The following example illustrates how you would configure subfolders named VBCode and CSCode to compile into separate assemblies:


<compilation debug="false">
<codeSubDirectories>
<add directoryName="VBCode" />
<add directoryName="CSCode" />
</codeSubDirectories>
</compilation>


Here is a link good to know in some cases where you need to run classes in both C# and VB.
http://msdn.microsoft.com/en-us/library/t990ks23.aspx