Access a HTML InputBox through the Code-Page

This is a discussion on "Access a HTML InputBox through the Code-Page" within the ASP.NET Forum section. This forum, and the thread "Access a HTML InputBox through the Code-Page are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > ASP.NET Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 7th, 2005, 16:07
New Member
Join Date: Nov 2005
Age: 39
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Access a HTML InputBox through the Code-Page

I have a HTML control Inputbox:
<INPUT type="text" onkeyup="chkText(tester.value)" id="tester">

I want to access it through my codepage when I press a button


PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim strMessage As HtmlInputText
strMessage =
Me.tester
Dim strScript AsString = "<script language=JavaScript>alert('" & strMessage.Value & "');</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
EndIf

EndSub

the error I get is:
Object reference not set to an instance of an object.

I want to keep the textbox client side validation because I check on every keyup. Is there any way to grab the text from the inputbox and use.

Thanks
Bob
Reply With Quote

  #2 (permalink)  
Old Nov 8th, 2005, 00:20
Anonymous User
Guest
Posts: n/a
Re: Access a HTML InputBox through the Code-Page

You need to be using a server-side control to access it in server-side script. Try using

<asp:TextBox id="tester" runat="server"></asp:TextBox>

and access it's value in your click event as tester.text

and that needs to be within a <form id="form1" runat=server></form> element for .NET to treat it as a post-back.
Reply With Quote
  #3 (permalink)  
Old Nov 8th, 2005, 13:12
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Re: Access a HTML InputBox through the Code-Page

Look at this example I have put together for you, it should help you out. It might also be of use to some other areas of your asp.net coding.

htmlcontrol.aspx
Code: Select all
<%@ Page Language="VB" Inherits="Webforumz.ExposeHtmlControl" src="htmlcontrol.aspx.vb" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
 <title>HTML Control</title>
 <script language="javascript" type="text/javascript">
  function jsValidate()
   {
   alert('Key pressed')
   }
 
  function jsAlert()
   {
   alert('You clicked submit')
   }
 </script>
</head>
<body>
<form runat="server">
 
 <input type="text" id="txt_htmlinput" runat="server" onKeyUp="jsValidate()" /><asp:Button id="btn_submit" runat="server" onclick="btn_submit__Click" Text="Submit" />
 
 <p><asp:Label id="lbl_message" runat="server" /></p>
</form>
</body>
</html>
htmlcontrol.aspx.vb
Code: Select all
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Namespace Webforumz
Public Class ExposeHtmlControl
 Inherits Page
 
'=========================================================================================================================================================================================================== 
' Declarations
 Protected WithEvents txt_htmlinput As HtmlControl
 Protected WithEvents btn_submit As Button
 Protected WithEvents lbl_message As Label
 
'=========================================================================================================================================================================================================== 
' Page Events
 
 Sub Page_Load(sender As Object, e As EventArgs)
 
  If not IsPostback()
   ' Add JS event to 'btn_submit'
   btn_submit.Attributes.Add("onclick", "jsAlert()")
  End If
 End Sub
 
 
'=========================================================================================================================================================================================================== 
' Click Events
 Sub btn_submit__Click(s As Object, e as EventArgs)
  lbl_message.text = txt_htmlinput.Attributes("value")
 End Sub
'=========================================================================================================================================================================================================== 
End Class
End Namespace
Hope that helps

Last edited by u2orange; Nov 8th, 2005 at 13:15.
Reply With Quote
  #4 (permalink)  
Old Nov 9th, 2005, 11:43
New Member
Join Date: Nov 2005
Age: 39
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Access a HTML InputBox through the Code-Page

Yes thanks, I could have sworn I tried it like that??
Reply With Quote
  #5 (permalink)  
Old Nov 10th, 2005, 12:34
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Access a HTML InputBox through the Code-Page

Have you got is sussed yet?
Reply With Quote
  #6 (permalink)  
Old Nov 10th, 2005, 12:58
New Member
Join Date: Nov 2005
Age: 39
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Access a HTML InputBox through the Code-Page

I think I see what my problem was. I was assuming that a web textbox was the same as a HTML textbox with "runat"=server. I now see that web textbox is stricly code-back page while HTML textbox can be seen in HTML script side and also code-back page.
Reply With Quote
Reply

Tags
access, html, inputbox, through, codepage

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a html code to make a page a certain size allstar Web Page Design 4 May 5th, 2008 20:25
How to connect the microsoft access database using HTML page mazenbluee Databases 5 Nov 21st, 2007 06:49
Display link code in html page nate2099 Web Page Design 13 Oct 11th, 2007 23:57
Access into HTML JTWork Web Page Design 3 Feb 7th, 2007 07:05
code error with Access madhuri.t Classic ASP 1 Feb 1st, 2006 17:47


All times are GMT. The time now is 20:59.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43