-
Mar 31st, 2012, 12:39 PM
#1
Thread Starter
Member
Problem getting value from textbox from one page to another with findcontrol
Hi
I have a MasterPage with a Textbox and an imageButton, one this MasterPage im using a web.Sitemap and global.asax for navigation, its works fine.
Im im one the page http://localhost:49207/ebbe/default.aspx i get this in the browser bc of the global.asax http://localhost:49207/ebbe/Butikken
So its works fine the navigation.
My problen is that when i type ind a value in the textbox on the masterpage and click the imageButton its then PostBackUrl="~/imailtest.aspx" that page isent using the masterpage but its looking for the id for the textbox on the masterpage.
But every time i hit the imagebutton i get this error:
HttpException was unhandled by user code.
The file /ebbe/Butikken do not exsist.
And it ref to the codeline ct=Me.Prev..... line.
So its PostBack me from the default.aspx (With masterpage) to the imailtest.aspx as it need to, i just cant get the vaule from the textbox id="newsletter" from the masterpage.
bc. it cant find the page.
I hope someone can help me.
My imailtest.aspx Code_Behind is:
Code:
Partial Class imailtest
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim emailvalue As String
Dim ct As New Control
ct = Me.PreviousPage.Master.FindControl("newsletter")
emailvalue = CType(ct, TextBox).Text
ema.Text = emailvalue
End Sub
End Class
-
Mar 31st, 2012, 07:26 PM
#2
Re: Problem getting value from textbox from one page to another with findcontrol
Instead of me.previouspage.master.Findcontrol try plain Master.FindControl
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 1st, 2012, 04:37 AM
#3
Thread Starter
Member
Re: Problem getting value from textbox from one page to another with findcontrol
Originally Posted by sapator
Instead of me.previouspage.master.Findcontrol try plain Master.FindControl
Hi
If i use
ct = Master.FindControl("newsletter")
i get this error
NullReferenceException was unhandled by user code.
Object reference not set to an instance of an object.
-
Apr 1st, 2012, 04:58 PM
#4
Re: Problem getting value from textbox from one page to another with findcontrol
I assume that you have a textbook with id newsletter on the master page.
Try this:
(make changes as i don't have vs here to type correctly)
Code:
Dim mpTextBox As textbox
mpTextbox = _
CType(Master.FindControl("newsletter"), _
Textbox)
If nothing get on you either have some issue with the control or masterpage is changing the name of the control when rendered but i have to have vs present to do test.
If you still have a problem use a simple portion of you code(1 masterpage with one textbox and an inherited page) and try testing to see if it work there.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 2nd, 2012, 03:10 AM
#5
Thread Starter
Member
Re: Problem getting value from textbox from one page to another with findcontrol
Im still getting the error, i have made a simple ex. and i get the error there to.
hope u can help, if u get the ex pages.
My sites is:
MasterPage.Master
Code:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<asp:TextBox ID="GetMailInfo" runat="server" Text="Tilmeld dig til vores Nyhedsbrev"></asp:TextBox>
<asp:ImageButton runat="server" ID="btnSubscribe" ImageUrl="~/add/image/btntilmeld.png" PostBackUrl="~/getmail.aspx"></asp:ImageButton>
</form>
</body>
</html>
Default.aspx
Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Content of Default.aspx
</asp:Content>
getmail.aspx
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="getmail.aspx.vb" Inherits="getmail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
getmail.aspx.vb
Code:
Partial Class getmail
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mpTextBox As TextBox
mpTextBox = CType(Master.FindControl("GetMailInfo"), TextBox)
Label1.Text = mpTextBox.ToString
End Sub
End Class
-
Apr 2nd, 2012, 11:38 AM
#6
Thread Starter
Member
Re: Problem getting value from textbox from one page to another with findcontrol
Hi i use this on getmail.aspx.vb then it works
Code:
Dim mpTextBox As TextBox = CType(Me.PreviousPage.Master.FindControl("GetMailInfo"), TextBox)
Label1.Text = mpTextBox.text
But if i then get back to my old code, where i use global.asax and routes then it will not work and if i add this to my ex.code, then the code findcontrol will not work.
Can u help me if u look at the ex and add this
default.aspx.vb
Code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.Url.AbsolutePath = "/TESTSLET/Default.aspx" Then
Response.Redirect(Request.Url.AbsoluteUri.Replace("/Default.aspx", "/FrontPage"))
End If
End Sub
End Class
Global.asax
Code:
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
'///// Denne linje er den der kalder Sub'en RegisterRoutes ved opstart, er meget vigtig. /////
RegisterRoutes(RouteTable.Routes)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
'///// Dette Sub er vigtig i Routes, sammen med import namespace System.Web.Routing. /////
Sub RegisterRoutes(ByVal routes As RouteCollection)
'for de forskellige link adresses/ruter skal der laven en
routes.MapPageRoute("", _
"FrontPage", _
"~/Default.aspx")
' adresse nr. 2
routes.MapPageRoute("", _
"GettingTheMail", _
"~/getmail.aspx")
End Sub
</script>
-
Apr 2nd, 2012, 08:30 PM
#7
Re: Problem getting value from textbox from one page to another with findcontrol
not sure what you want me to look at the code you posted.
Also are you doing all these to global.aspx?I don't see that but don't do it anyhow.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|