Value passing

miwaypro

Freshman
Joined
Oct 18, 2003
Messages
36
Location
Malaysia
hi all,

This is my code, which give me an error of "name" is not declared

Visual Basic:
'code for WebForm1.aspx.vb
Sub submit(ByVal sender As Object, ByVal e As EventArgs)
        If name.value <> "" Then
            p1.InnerHtml = "Welcome " & name.value & "!"
        End If
    End Sub

Code for WebForm1.aspx

Visual Basic:
<form runat="server">
Enter your name: <input id="name" type="text" size="30" runat="server" />
<br /><br />
<input type="submit" value="Submit" OnServerClick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
The name is my input id, how to pass the value?
 
In order to reference a control, the code-behind must know about the control. In your case, the code-behind has no idea the control exists, probably because the control is not declared in your code-behind file.

If you're using VS 2003, you can switch to design view, and then switch back to HTML view. That should add the control.

Or, you could declare the control yourself.

Visual Basic:
Protected WithEvents name as HtmlInputText
 
sbauer said:
In order to reference a control, the code-behind must know about the control. In your case, the code-behind has no idea the control exists, probably because the control is not declared in your code-behind file.

If you're using VS 2003, you can switch to design view, and then switch back to HTML view. That should add the control.

Or, you could declare the control yourself.

Visual Basic:
Protected WithEvents name as HtmlInputText

ok, thank you very much
 
Back
Top