Hello overyone,

I have a question about web forms.
I've set up a web service and i'm now trying to make a registration page.
The one thing I couldn't figure out is how to handle events. For example, I have a simple button with id="Register", how can I handle that event?

I can't seem to call a textbox on my form like you usually do in a VB form.

Can somebody guide me through the basics? Perhaps a link for newbies?

Googling for information isn't as easy as I thought it would be :(

Recommended Answers

All 4 Replies

Any controls that you place on the page (the .aspx) that you want to use server side need to have an ID and the attribute runat="server". You can then access on the code-behind page by using its ID.
For example, if you had a text box :

<asp:Textbox id="textBox1" runat="server" />

It could be accessed with:

textBox1.Text = "Hello World"

If a control is clickable (such as a radio button, button, etc) you also need to specify the onCLick="someMethod()" in the .aspx page and then include the same method in the code behind. For a button it would be:

<asp:Button id="button1" runat="server" text="Click me" onCLick="button1_Click" />

code behind:
sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
...
end sub

I hope that helps. The MSDN site is pretty useful when starting out (or at any other time...)

Two types of event you can create.
One is Client Side (Using Javascript) or Server Side Using (Any Server Side Language- Here VB.Net)

So which one you want???

@kingsonprisonic: I want to create server-sided event handling, but I would like an example of eventhandling in jscript too if possible?
@hericles: Thanks for the info, altough I'm still having trouble, here's some code

<div class="Login">
            Login:<asp:TextBox ID="txtGebruikersnaam" runat="server"></asp:TextBox>
            Pawoord:<asp:TextBox ID="txtWachtwoord" runat="server"></asp:TextBox>
            <asp:Button ID="btnAanmelden" runat="server" style="text-align: center;" Text="Aanmelden" Height="22px" Width="72px" />
        </div>

So i've managed to create a sub for btnAanmelden (which is btnloggin in english by the way), but intellisense doesn't detect the two textboxes above the button.
As you can see, they are all server side. Here's what i've got in VB (code behind)

Sub btnAanmelden_Click(ByVal Sender As Object, ByVal e As EventArgs)
        txtGebruikersnaam.Text = "test"
    End Sub

txtGebruikersnaam gives me an error saying that it has not been declared and it might be due to it's protection level.
any suggestions?

Alright... pretty stupid of me but I found what was going wrong.
I imported my aspx pages and masterpages from a normal website project.
I copied most of the code to new pages and masterpages and everything is working as I expected :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.