Hi muhammad12,
Here is the working code you asked for.
I used conditional statements for displaying number and address of To and From.
HTML
Dispatched_Form
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dispatch Form</title>
<style>
body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; }
.container { width: 50%; margin: 50px auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); }
.form-row { display: flex; flex-wrap: wrap; margin-bottom: 20px; }
.form-group { flex: 1 1 calc(50% - 10px); margin-right: 20px; }
.form-group:last-child { margin-right: 0; }
label { display: block; font-weight: bold; margin-bottom: 5px; }
input[type=text],
select,
textarea,
input[type=number] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; font-size: 16px; }
.button-container { text-align: center; }
.btn-print { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; transition: background-color 0.3s; }
.btn-print:hover { background-color: #0056b3; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="form-row">
<div class="form-group">
<label for="DropDownList1">To:</label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem>Abdullah</asp:ListItem>
<asp:ListItem>muhammad</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="TextBox2">Item Name:</label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<label for="TextBox3">Quantity:</label>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Number"></asp:TextBox>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="TextBox4">Confirm To:</label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="TextArea1">Notes:</label>
<textarea id="TextArea1" runat="server" rows="4"></textarea>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="DropDownList2">From:</label>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem>abc</asp:ListItem>
<asp:ListItem>xyz</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="button-container">
<asp:Button ID="Button1" runat="server" Text="Print" OnClick="Button1_Click" CssClass="btn-print" />
</div>
</div>
</form>
</body>
</html>
PrintInfo
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Print Page</title>
<style>
body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; }
.container { width: 95%; margin: 50px auto; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); padding: 20px; display: flex; justify-content: space-between; }
.info-section { flex: 1; padding: 10px; }
.info-section h2 { text-align: center; margin-bottom: 20px; }
.info-section label { font-weight: bold; }
.info-section p { margin: 0; }
.print-button { text-align: center; margin-top: 20px; }
.btn-print { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; transition: background-color 0.3s; }
.btn-print:hover { background-color: #0056b3; }
@media print {
.container { width: 100%; margin: 0; box-shadow: none; }
.print-button { display: none; }
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="form-group">
<label><b>To:</b></label>
<asp:Label ID="lblTo" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>To: PO#</b></label>
<asp:Label ID="lblToAddress" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>To: Number</b></label>
<asp:Label ID="lblToNumber" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>Item Name:</b></label>
<asp:Label ID="lblItemName" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>Quantity:</b></label>
<asp:Label ID="lblQuantity" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>Confirm To:</b></label>
<asp:Label ID="lblConfirmTo" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>Notes:</b></label>
<asp:Label ID="lblNotes" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>From:</b></label>
<asp:Label ID="lblFrom" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>From: PO#:</b></label>
<asp:Label ID="lblFromAddress" runat="server"></asp:Label>
</div>
<div class="form-group">
<label><b>From: Number:</b></label>
<asp:Label ID="lblFromNumber" runat="server"></asp:Label>
</div>
</div>
<div class="container">
<div class="info-section" style="text-align: right;">
<h2>Date & Time</h2>
<asp:Label ID="lblDateTime" runat="server"></asp:Label>
</div>
</div>
<div class="print-button">
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="window.print();return false;" CssClass="btn-print" />
</div>
</form>
</body>
</html>
Dispatched_Form
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// Clear any existing session variables
Session.Clear();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// Store form data in session variables
Session["To"] = DropDownList1.SelectedItem.Text;
//Setting 'To' Number and Address based on DropDownList selection
if (Session["To"].ToString() == "Abdullah")
{
Session["ToAddress"] = "Street #1, Ajman UAE";
Session["ToNumber"] = "+1 (555) 123-4567";
}
else if (Session["To"].ToString() == "muhammad")
{
Session["ToAddress"] = "456 Elm Avenue, Springfield, Canada";
Session["ToNumber"] = "+1 (555) 789-0123";
}
Session["ItemName"] = TextBox2.Text;
Session["Quantity"] = TextBox3.Text;
Session["ConfirmTo"] = TextBox4.Text;
Session["Notes"] = TextArea1.Value;
Session["From"] = DropDownList2.SelectedItem.Text;
//Setting 'From' Number and Address based on DropDownList selection
if (Session["From"].ToString() == "abc")
{
Session["FromAddress"] = "132, My Street, New York 12401.";
Session["FromNumber"] = "(212) 555-1234";
}
else if (Session["From"].ToString() == "xyz")
{
Session["FromAddress"] = "246 Pine Road, Paris, France";
Session["FromNumber"] = "+33 6 12 34 56 78";
}
// Redirect to the next page for printing
Response.Redirect("PrintInfo.aspx");
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
'Clear any existing session variables
Session.Clear()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
'Store form data in session variables
Session("To") = DropDownList1.SelectedItem.Text
'Setting 'To' Number and Address based on DropDownList selection
If Session("To").ToString() = "Abdullah" Then
Session("ToAddress") = "Street #1, Ajman UAE"
Session("ToNumber") = "+1 (555) 123-4567"
ElseIf Session("To").ToString() = "muhammad" Then
Session("ToAddress") = "456 Elm Avenue, Springfield, Canada"
Session("ToNumber") = "+1 (555) 789-0123"
End If
Session("ItemName") = TextBox2.Text
Session("Quantity") = TextBox3.Text
Session("ConfirmTo") = TextBox4.Text
Session("Notes") = TextArea1.Value
Session("From") = DropDownList2.SelectedItem.Text
'Setting 'From' Number and Address based on DropDownList selection
If Session("From").ToString() = "abc" Then
Session("FromAddress") = "132, My Street, New York 12401."
Session("FromNumber") = "(212) 555-1234"
ElseIf Session("From").ToString() = "xyz" Then
Session("FromAddress") = "246 Pine Road, Paris, France"
Session("FromNumber") = "+33 6 12 34 56 78"
End If
'Redirect to the next page for printing
Response.Redirect("PrintInfo.aspx")
End Sub
PrintInfo
C#
protected void Page_Load(object sender, EventArgs e)
{
// Check if session variables exist and are not null
if (Session["To"] != null)
lblTo.Text = Session["To"].ToString();
if (Session["ToAddress"] != null)
lblToAddress.Text = Session["ToAddress"].ToString();
if (Session["ToNumber"] != null)
lblToNumber.Text = Session["ToNumber"].ToString();
if (Session["ItemName"] != null)
lblItemName.Text = Session["ItemName"].ToString();
if (Session["Quantity"] != null)
lblQuantity.Text = Session["Quantity"].ToString();
if (Session["ConfirmTo"] != null)
lblConfirmTo.Text = Session["ConfirmTo"].ToString();
if (Session["Notes"] != null)
lblNotes.Text = Session["Notes"].ToString();
if (Session["From"] != null)
lblFrom.Text = Session["From"].ToString();
if (Session["FromAddress"] != null)
lblFromAddress.Text = Session["FromAddress"].ToString();
if (Session["FromNumber"] != null)
lblFromNumber.Text = Session["FromNumber"].ToString();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'Check if session variables exist And are Not null
If Session("To") IsNot Nothing Then lblTo.Text = Session("To").ToString()
If Session("ToAddress") IsNot Nothing Then lblToAddress.Text = Session("ToAddress").ToString()
If Session("ToNumber") IsNot Nothing Then lblToNumber.Text = Session("ToNumber").ToString()
If Session("ItemName") IsNot Nothing Then lblItemName.Text = Session("ItemName").ToString()
If Session("Quantity") IsNot Nothing Then lblQuantity.Text = Session("Quantity").ToString()
If Session("ConfirmTo") IsNot Nothing Then lblConfirmTo.Text = Session("ConfirmTo").ToString()
If Session("Notes") IsNot Nothing Then lblNotes.Text = Session("Notes").ToString()
If Session("From") IsNot Nothing Then lblFrom.Text = Session("From").ToString()
If Session("FromAddress") IsNot Nothing Then lblFromAddress.Text = Session("FromAddress").ToString()
If Session("FromNumber") IsNot Nothing Then lblFromNumber.Text = Session("FromNumber").ToString()
End Sub
Screenshot