Webforumz's RSS FeedRSS Webforumz RegistrationRegister Contact Webforumz StaffContact

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.


 Subscribe in a reader

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

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 7th, 2005, 17: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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old Nov 8th, 2005, 01: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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 8th, 2005, 14: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 14:15.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 9th, 2005, 12: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??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 10th, 2005, 13: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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 10th, 2005, 13: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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 21:25
How to connect the microsoft access database using HTML page mazenbluee Databases 5 Nov 21st, 2007 07:49
Display link code in html page nate2099 Web Page Design 13 Oct 12th, 2007 00:57
Access into HTML JTWork Web Page Design 3 Feb 7th, 2007 08:05
code error with Access madhuri.t Classic ASP 1 Feb 1st, 2006 18:47


All times are GMT. The time now is 19:51.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8