Click to See Complete Forum and Search --> : How to access one web form from other web form in ASP.Net
diamond4u
April 1st, 2003, 11:13 PM
Hi,
I am new to ASP.Net.
I have two web forms & I want to access a property/function of one web form from other web form's event.
Can I do that? If yes, then how should I go?
Looking for a quick solution,
Diamond :confused:
shethashish_a
April 3rd, 2003, 02:35 AM
Hi,
I don't think u can do it.
A web form runs momentarily and terminates as soon as it completes the processing and had sent the output to the client.
You can use Sever.Execute method to process the second web form from the first web form but this will give u the html output of the second form. I don't think that there is a way to access a property or method of a web form from another web form.
Ashish
chmurali
April 3rd, 2003, 03:25 AM
Hi
Try this:
Form1.aspx.vb :: Use Namespace in the begining of the page.
'--Code starts
Namespace Murali
Public Class form1
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = myfunction(TextBox1.Text)
End Sub
Function myfunction(ByVal a As Integer) As Integer
Return a * 10
End Function
End Class
End Namespace
'--- code ends
Form2.aspx.vb : call the myfunction (form1's function ) in 2nd Aspx page:
'--Code begins....
Public Class Form2
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim x As New Murali.form1()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = x.myfunction(TextBox1.Text)
End Sub
End Class
'-- Code ends..
cheers
Murali
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.