We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,610 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Web Form: event handling

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 :(

3
Contributors
4
Replies
20 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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...)

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

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
Posting Whiz in Training
268 posts since Nov 2009
Reputation Points: 61
Solved Threads: 54
Skill Endorsements: 0

@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?

selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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 :)

selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by hericles and kingsonprisonic

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0689 seconds using 2.68MB