?
Solved

FormViews ASP. Net

Posted on 2015-02-12
5
Medium Priority
?
36 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 2000 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 2000 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 2000 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 2000 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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