In vb6 I would do:
But how do I do this on a web ASP.NET page?VB Code:
If txtUsername.Text = vbNullstring Then MsgBox "Please enter a correct woof!" txtUsername.SetFocus End If
The txtUsername doesn't have a SetFocus method :(
Woka
Printable View
In vb6 I would do:
But how do I do this on a web ASP.NET page?VB Code:
If txtUsername.Text = vbNullstring Then MsgBox "Please enter a correct woof!" txtUsername.SetFocus End If
The txtUsername doesn't have a SetFocus method :(
Woka
You would have to use client side script.
(assuming you do validation on a button click)
page script:
vb form code:Code:<script>
function IsEmpty()
{
if(document.getElementById("TextBox1").value == '')
{
alert('You must enter text!');
document.getElementById("TextBox1").focus();
}
return false;
}
</script>
You have to be sure and return false from the script function to prevent postback.VB Code:
If Not Page.IsPostBack Then Button1.Attributes.Add("OnClick", "script:return IsEmpty()") End If
You are kidding right?
I am writing this using .NET 2003, and it doesn't have a setfocus method? Is that correct? If so, how bloody stupid :(
*sigh*
*sulk*
Woka
You are not understanding how client/server side processing works.
ASP.NET pages are stateless. How do you expect your server to remember that you want to set the focus to 'TextBox1' after the page has been posted?
Whenever your page is posted back it can't possibly remember the value of a control unless you save the value to Session or Viewstate. That bogs down your server. You don't have to wait on the server to postback if you use a script.
Why do you hate Javascript? Just about every custom control I have ever seen uses it at some point.
I am learning .NET
I don'[t want to have to learn java at the same time, .NEt is bad enough on it's own :(
But if it's the only way...oh, can it be done using vbscript?
Woof
I know how you feel ;)
It took me a while to get used to the difference between client and server side processing. I hated the idea of Javascript. But you really have to learn very little script. I usually just search the net to find a script I need.
I don't know if it's possible in VB script. It should be but I go with Javascript because it's used a lot more frequently.
Try web validation controls. That gives your users a visual cue/explanation (depends how you set it up) on what's wrong with their entries without postback.Quote:
Originally posted by Wokawidget
I am learning .NET
I don'[t want to have to learn java at the same time, .NEt is bad enough on it's own :(
But if it's the only way...oh, can it be done using vbscript?
Woof
JavaScript is not very difficult to learn. It's small, and simple. Just a couple lessons and you'll be familiar enough to accomplish what you need.
Btw, I found that knowing ASP 3.0 and Javascript/html before hand was very helpful in understanding the entire concept of ASP.NET. :)