views:

25

answers:

2

i have simple html page with 3 textboxes.

<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
    <div>
        <input id="name" type="text" value="Amy" />
        <input id="email" type="text"  value="[email protected]"/>
        <input id="phone" type="text" value="2125552512" />
    </div>
    <input id="Submit1" type="submit" value="submit" />
</form>

Now when it loads default.aspx i have this code in the vb backend on page_load.

Dim tbName As TextBox = Page.FindControl("Name")
Dim tbPhone As TextBox = Page.FindControl("Phone")
Dim tbEmail As TextBox = Page.FindControl("Email")
If page.request("name") & "" <> "" AndAlso tbname IsNot Nothing Then
    tbname.text = page.request("name") 
End If
If page.request("email") & "" <> "" AndAlso tbEmail IsNot Nothing Then
    tbEmail.text = page.request("email") & ""
end If
If page.request("phone") & "" <> "" AndAlso tbphone IsNot Nothing Then
    tbPhone.text = page.request("phone") & ""
End If

The page loads but is these textboxes are empty. what am i doing wrong?

A: 

it is not like this that webform functionate.

First, your input in your form needs to be server control: ex <asp:TextBox runat="server" id="name" Text="value" />

Then in your codebehind file you do not have to go through Page.FindControl("YourInput") but only this.YourInput.Text

Gregoire
+1  A: 

If you want to be able to access those controls serverside, you'll need to add the runat="server" attribute to each of them.

Also, the TextBox type you're referencing is the ASP.NET control, which you aren't using. What you'd be using, once you add the runat="server" tags is HtmlInputText.

You can use the TextBox type by using the TextBox ASP.NET control instead of the <input> elements:

<asp:TextBox ID="name" runat="server" Value="Amy" />

If all your ASP.NET page is doing is processing the request from the form, then there's no need to reference any textbox or input controls - it won't be possible since they don't exist as ASP.NET controls. All you need to do is read the values from Request.QueryString.

If the intent is for the inputs to be visible and/or editable once they're on the ASP.NET page, I'd recommend moving the HTML form into your ASP.NET page.

Daniel Schaffer
why would i use <asp:textbox when my page is a .htm? first page is .htm and the values goto .aspx page.
redfer
Ah okay, I misunderstood that. Will update my question.
Daniel Schaffer