1,105,386 Community Members

Web Form: event handling

Member Avatar
selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
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...)

Member Avatar
kingsonprisonic
Posting Whiz in Training
265 posts since Nov 2009
Reputation Points: 42 [?]
Q&As Helped to Solve: 54 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
selman555
Newbie Poster
4 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 :)

Question Answered as of 2 Years Ago by hericles and kingsonprisonic
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: