Solved

FormViews ASP. Net

Posted on 2015-02-12
5
34 Views
Last Modified: 2016-06-23
Using 2 formviews, is there a way to updated sql database using a variable from each formviews.  How do I pass variable from the 1st formview to the 2nd?  I am really new to .net.....so be as clear as possible.
0
Comment
Question by:zraiford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40607368
Option 1:
In a module, add:

Public strVar as String

----------
In Form1, set a value to it like

strVar = "ABC"
------------
In Form2, use it

MessageBox.Show(strVar)
0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607371
There are some other ways of doing this using Friend scope we can discuss later if interested.

I just notice you are not talking about windows application. This was for winForms. For   webform, you can pass the values using session variables.

brb,

Mike
0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607385
Are you working with vb.net or c#?  I want to create a sample you you but it will be good to know language choice>

Here is partial code:
In webform1, I use  btnSave_Click event to save a phone number (entered into txtPhone control) into a session variable
' and then open Confirm.aspx (the second webform)
Protected Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
    Session("phone") = txtPhone.Text
    ' open confirm page
            Response.Redirect("Confirm.aspx")
 End Sub

Open in new window


I wait for your response to continue.

Mike
0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40607401
This is the code in the 1st webform (Default.aspx): You enter a phone number and click on save. It store the value you entered in to a session variable and the opens a second webform (Default2.aspx)
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Session["phone"] = txtPhone.Text;
        Response.Redirect("Default2.aspx");
    }
}

Open in new window


This the code in the second webform: When this webform opens, it writes the value in the session variable to the page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Session["phone"]);
    }
}

Open in new window

0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question