473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Callback With Master Pages [Help REALLY Appreciated]

Hello All and Advanced Thanks For Replying,
OS: XP Pro
IDE: Visual Studio 2005
..net Framework: 2.0.....

Problem: Getting An Error When trying to implement the following
CallBack on a content page that uses a master page (Code From
Professional asp.net 2.0 Book)

Error:
/************************************************** *********************************/
Line: 163
Char: 13

Error:'document.forms.0.TextBox1' is null or not an object

Code: 0
URL: http://localhost:1325/WebSite4/Exper...WthMaster.aspx
/************************************************** *********************************/
Code Behind
/************************************************** ***********************************/
Partial Class Experiment_WthMaster
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler

Dim _callbackResult As String = Nothing

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles Me.Load

Dim cbReference As String =
Page.ClientScript.GetCallbackEventReference(Me, "arg",
"GetRandomNumberFromServer", "context")
Dim cbScript As String = "function UseCallback(arg, context) {"
& cbReference & ";" & "}"

Page.ClientScript.RegisterClientScriptBlock(Me.Get Type(), _
"UseCallback", cbScript, True)
End Sub

Public Sub RaiseCallbackEvent(ByVal eventArgument As String)
Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackE vent
_callbackResult = Rnd().ToString()
End Sub

Public Function GetCallbackResult() As String Implements
System.Web.UI.ICallbackEventHandler.GetCallbackRes ult
Return _callbackResult
End Function
End Class
/************************************************** ***********************************/

Code ASPX
/************************************************** ***********************************/
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="Experiment_WthMaster.aspx.vb"
Inherits="Experiment_WthMaster" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<script type="text/javascript">
function GetNumber(){
UseCallback();
}

function GetRandomNumberFromServer(TextBox1, context){
document.forms[0].TextBox1.Value = TextBox1;
}
</script>
<div>
<input id="Button1" type="button" value="Get Random Number"
onclick="GetNumber()" />
<br />
<br />
<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
</div>

</asp:Content>
/************************************************** ***********************/
Help REALLY Appreciated
Thanks
Farooq

Dec 13 '05 #1
1 1858
>document.forms[0].TextBox1.Value = TextBox1;

This is your problem. When you use master pages (or anything else that
wraps a container around controls), the framework changes the names of
the controls to ensure uniqueness.

What you need to do is change this so that the server side code adds the
ClientID of the control. Something like...

document.forms[0].<%#TextBox1.ClientID%>.Value = TextBox1;

There have been a couple of threads about this in the past couple of
weeks. If this doesn't make sense, look back through the archives to see
more discussion.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Dec 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carl Gilbert | last post by:
Hi I am trying to get a site working with some 1&1 web space. I have the MS Business Pro account which has ASP.NET Support and SQL Server. I am trying to get an online gallery to work but I...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
7
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
8
by: otto | last post by:
Hi, all: I have a problem with the inclusion of .js files in mu .aspx pages when using Master Pages. I try to explain it. If I make a web project without master pages I simply put in the head...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
2
by: Russ Green | last post by:
I'm really struggling to find how to do this with easy to follow VB.NET samples. I have built a website with about 4 - 5 content pages using 1 master page. http://www.openarch.co.uk/default.aspx...
1
by: Joey | last post by:
Hey guys, here's what I have... To help manage browser windows with session state on the server, I have some javascript code in one of my master pages that gets planted into most (content) pages...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.