CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Location
    Pune
    Posts
    8

    Unhappy How to access one web form from other web form in ASP.Net

    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

  2. #2
    Join Date
    May 2002
    Location
    Hyderabad
    Posts
    76
    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
    Ashish Sheth

  3. #3
    Join Date
    Mar 2003
    Posts
    4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured