Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 39
  • Last Modified:

FormViews ASP. Net

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
zraiford
Asked:
zraiford
  • 4
4 Solutions
 
Mike EghtebasDatabase and Application DeveloperCommented:
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
 
Mike EghtebasDatabase and Application DeveloperCommented:
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
 
Mike EghtebasDatabase and Application DeveloperCommented:
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
 
Mike EghtebasDatabase and Application DeveloperCommented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now