Populating textbox based on user logged in - c#

I'm new to c# and I'm trying to build my skills without using any of the wizard tools (eg. login wizard) provided in .net. So far I've been successful in creating a very basic login website.
I'm trying to create a user profile page that will display all the data (first name, last name, etc) of the user logged in.
Text boxes on the page should populate on Page_Load but they are not.
here is the aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="UserProfile.aspx.cs" Inherits="TimeHub2.UserProfile" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="UserProfile" runat="server">
<div class="header">
<h1>TimeHub</h1>
<ul>
<li>my cards</li>
<li>profile</li>
<li>help</li>
<li><asp:Label runat="server" ID="userloggedin"></asp:Label></li>
<li><asp:button runat="server" id="buttonLogout" text="Log Out" onClick="logOutClick" /></li>
</ul>
</div>
<div>
<label for="username">username</label>
<asp:TextBox runat="server" id="username"></asp:TextBox>
<label for="first_name">first name</label>
<asp:TextBox runat="server" ID="first_name"></asp:TextBox>
<label for="middle_intial">middle initial</label>
<asp:TextBox runat="server" ID="middle_intial"></asp:TextBox>
<label for="last_name">last name</label>
<asp:TextBox runat="server" ID="last_name"></asp:TextBox>
</div>
<div>
<label for="star">star</label>
<asp:TextBox runat="server" ID="star"></asp:TextBox>
<label for="rank">rank</label>
<asp:TextBox runat="server" ID="rank"></asp:TextBox>
</div>
<div>
<label for="assignment">assignment</label>
<asp:TextBox runat="server" ID="assignment"></asp:TextBox>
<label for="regular_shift">regular shift</label>
<asp:TextBox runat="server" ID="regular_shift"></asp:TextBox>
</div>
<div>
<label for="contact_phone">contact phone</label>
<asp:TextBox runat="server" ID="contact_phone"></asp:TextBox>
<label for="phone_type">phone type</label>
<asp:DropDownList ID="phone_type" runat="server">
<asp:ListItem>home</asp:ListItem>
<asp:ListItem>cell</asp:ListItem>
</asp:DropDownList>
<label for="email">sfpd email</label>
<asp:TextBox runat="server" ID="email" TextMode="Email"></asp:TextBox>
</div>
<div>
<asp:Button runat="server" ID="save" Text="update profile" />
</div>
</form>
</body>
</html>
Here is the c# code I have written to populate the TextBox "first_name":
protected void Page_Load(object sender, EventArgs e)
{
//show user logged in
if (Session["New"] != null)
{
userloggedin.Text = Session["New"].ToString();
}
//else redirect to login
else
Response.Redirect("Login.aspx");
SqlConnection conn = new SqlConnection(Connection-String);
SqlDataReader profileReader = null;
string userDataQuery = "SELECT * FROM dbo.users WHERE username ='" + userloggedin.Text + "'";
conn.Open();
SqlCommand cmd = new SqlCommand(userDataQuery, conn);
profileReader = cmd.ExecuteReader();
while(profileReader.Read())
{
first_name.Text = profileReader["first_name"].ToString();
}
conn.Close();
}
Thanks for your help

solved my own problem. The issue was in the column names of my database. my naming convention used underscores in the column names, however I omitted the underscore for the column in question. Rather than 'first_name' as it should have been, it was 'first name'.

If You are retrieving Only FirstName then There is no need to use *
try like this
string userDataQuery = "SELECT first_name FROM dbo.users
WHERE username ='" + userloggedin.Text + "'";
while(profileReader.Read())
{
first_name.Text = profileReader["first_name"]==DBNull.Value ? "":
profileReader["first_name"].ToString();
}
Beware of SQL Injection Always Use SqlParameter

Related

Why is the textbox in my ASP.NET webform always empty

This is my markup:
<%# Page Title="" Language="C#" MasterPageFile="~/User/Default.Master" AutoEventWireup="true" CodeBehind="Consulation.aspx.cs" Inherits="PetShop.User.Consulation" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script>
window.onload = function () {
var second = 5;
setTimeout(function () {
document.getElementById("<%=lblMsg.ClientID%>").style.display = "none";
}, second * 1000)
}
</script>
<link href="../CSSandJS/StyleCss/consulation.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!-- Slider -->
<section id="Slider">
<div class="aspect-ratio-169">
<img src="../CSSandJS/images/bg_1.jpg" alt="">
<img src="../CSSandJS/images/bg_2.jpg" alt="">
<img src="../CSSandJS/images/bg_3.jpg" alt="">
<img src="../CSSandJS/images/bg_4.jpg" alt="">
</div>
<div class="dot-container">
<div class="dot active"></div>
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</section>
<!-- End Slider -->
<!-- Free Consulation -->
<section class="contact">
<div class="container-contact">
<h1>Đặt lịch hẹn</h1>
<div class="row">
<div class="contact-img">
<img src="../CSSandJS/images/bg_1.jpg" alt="" width="400">
</div>
<div class="input-infor">
<div class="form">
<div class="dbl-field">
<asp:DropDownList ID="ddlCategory" runat="server" CssClass="form-control option field-mail listOp" DataSourceID="SqlDataSource1" DataTextField="TENDV" DataValueField="MADV" AppendDataBoundItems="true">
<asp:ListItem Value="0">Chọn danh mục</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cs %>" SelectCommand="SELECT [MADV], [TENDV] FROM [DICHVU]"></asp:SqlDataSource>
</div>
<div class="dbl-field">
<div class="field-mail">
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-control input" placeholder="Nhập email" required></asp:TextBox>
<i class="ri-mail-line"></i>
</div>
</div>
<div class="dbl-field">
<div class="field">
<asp:TextBox ID="txtNameAcc" runat="server" CssClass="form-control input" placeholder="Nhập tên"></asp:TextBox>
<i class="ri-user-line"></i>
</div>
<div class="field">
<asp:TextBox ID="txtSDT" runat="server" CssClass="form-control input" placeholder="Nhập số điện thoại" MaxLength="11"></asp:TextBox>
<i class="ri-phone-line"></i>
</div>
</div>
<div class="dbl-field">
<div class="field">
<asp:TextBox ID="txtNgay" runat="server" CssClass="form-control input" TextMode="Date"></asp:TextBox>
<i class="ri-calendar-2-line"></i>
</div>
<div class="field">
<asp:TextBox ID="txtTime" runat="server" CssClass="form-control input" placeholder="Nhập giờ hẹn" MaxLength="5" TextMode="SingleLine"></asp:TextBox>
<i class="ri-time-line"></i>
</div>
</div>
<div class="message">
<asp:TextBox ID="txtDescription" runat="server" CssClass="form-control textarea" placeholder="Tin nhắn" TextMode="MultiLine"></asp:TextBox>
<i class="ri-message-2-line"></i>
</div>
<div class="button-area">
<asp:Button ID="Add" runat="server" Text="Gửi lịch hẹn" class="btn btn-primary button" OnClick="Add_Click"/>
<asp:Label ID="lblMsg" runat="server" Visible="false"></asp:Label>
<%--<asp:linkbutton id="submitcal" runat="server" cssclass="btn btn-primary button" OnClick="Add_Click">gửi lịch hẹn</asp:linkbutton>--%>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- End Free Consulation -->
</asp:Content>
The textbox doesn't get any value when I debug the program.
I have tested the stored procedure in SQL Server and it works fine. But the data returned from the SQL code is empty.
My button submit code:
namespace PetShop.User
{
public partial class Consulation : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
}
private void clear()
{
txtEmail.Text = string.Empty;
txtDescription.Text = string.Empty;
txtNameAcc.Text = string.Empty;
txtSDT.Text = string.Empty;
txtNgay.Text = string.Empty;
txtTime.Text = string.Empty;
ddlCategory.ClearSelection();
}
protected void Add_Click(object sender, EventArgs e)
{
string actionName = string.Empty;
bool isValidToExcute = true;
con = new SqlConnection(Connection.GetConnectionString());
cmd = new SqlCommand("Add_KHaddLH", con);
cmd.Parameters.AddWithValue("#Action", "INSERT4KH");
cmd.Parameters.AddWithValue("#MaDv", ddlCategory.SelectedValue);
cmd.Parameters.AddWithValue("#EMail", txtEmail.Text.Trim());
cmd.Parameters.AddWithValue("#Ten", txtNameAcc.Text.Trim());
cmd.Parameters.AddWithValue("#Sdt", txtSDT.Text.Trim());
cmd.Parameters.AddWithValue("#NgayHen", txtNgay.Text.ToString());
cmd.Parameters.AddWithValue("#GioHen", txtTime.Text.Trim());
cmd.Parameters.AddWithValue("#GhiC", txtDescription.Text.Trim());
if (isValidToExcute)
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
cmd.ExecuteNonQuery();
actionName = "gửi";
lblMsg.Visible = true;
lblMsg.Text = "Lịch hẹn " + actionName + " thành công!";
lblMsg.CssClass = "alert alert-success";
clear();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = "Lỗi !!!" + ex.Message;
lblMsg.CssClass = "alert alert-danger";
}
finally
{
con.Close();
}
}
}
}
}
I think the error lies in the page reload, because when submitting it will delete all the data in the textbox and then enter.
I've tried adding some commands to the button but still can't handle that it keeps losing textbox data.
I update code behind and markup.
Support me,
Thank.
Ok, so that helps a boatload.
if we have this code:
protected void Add_Click(object sender, EventArgs e)
{
string actionName = string.Empty;
bool isValidToExcute = true;
Debug.Print(txtEmail.Text);
output:
So, you might want to put a break point in, or simple add some debug.prints, and see which text box controls are "empty". But, just looking at what you have, those text boxes should be ok.
And including page-load, shows that you not say running the "clear" routine you have. (so, having included the page load event eliminates about 100 possible issues here. This is VERY much why posting some of your code allows the public here to eliminate a 100 "back and forth" suggestions.) So, for example, had you included "clear" routine in page load, then of course page load fires each and every time BEFORE a button click event, so code in page load is VERY OFTEN suspect here. But, since you don't have code in page load event, we scratch that off the table.
So, far, the controls look to have values, but I suggest you add a break point, or some debug.prints as per above to be 100% sure that the controls in fact do not have values.
Also, just pasting in some of the markup, we see things like this:
So, you do have stray "garbage" in a number of places. (not good).
As it stands, with the posted markup, I MOST certainly do get/see/have/enjoy/observe that the text boxes are intact, do have values.
Given we can't re-produce your issue?
I suggest creating a blank new page, drop in some of those controls, and try a test button - (don't even bother with the database save code - we NOT gone that far down the debugging road just yet).
So, only thing so far?
Are you 100% sure the text boxes don't have values, and you tested this BEFORE any of the database save code runs?
and do remove the stray "required" markup in that txtEmail box, the editor even HONKS OUT AT YOU that the markup is bad as per above screen shot.
In fact, drop in another button on the form, and its only job would be to debug print out the text boxes - does that work?
As it stands now, you don't have a re-producable error, and the community in general here has not, does not see your error, nor are we the viewing public EVEN able to re-produce that these text boxes don't have values.
As a result, there information we don't have to re-produce the error.
I suggest building a page with just the txtEmail that is blank, and a simple button. if that works, then start adding markup from that other page until it stops working, since we here can't re-produce your issue with the provided code and markup you have provided.
And, since you using a master page, then check if page load in master page has any code that runs on page load.

Session on Textbox with asp.net and c#

I'am try to make a session on a Textbox in asp.net, that textbox allows the user to enter values from 1-4, but whenever I click on button "book", it gives me an null pointer exception, I am using FindControl function from my c# backend.
Here's my code
.aspx page
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="hotels_main.aspx.cs" Inherits="Hotel_Mangement.hotels_main" %>
<asp:Content ID="Content1" ContentPlaceHolderID="hotels_main" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="free website templates, hotel and travel, CSS, XHTML, design layout" />
<meta name="description" content="Hotel and Travel - free website template provided by templatemo.com" />
<link href="/css/templatemo_style.css" rel="stylesheet" type="text/css" />
<div id="templatemo_container">
<!-- Free Website Template by www.TemplateMo.com -->
<div id="templatemo_content">
<div id="content_left" style="background-color:#2C3E50">
<div class="content_left_section">
<div class="content_title_01">Confirm Your Booking</div>
<form id="form1" >
<div class="form_row">
<br /><br />
<big>Check in:</big>
<asp:Calendar ID="checkin" runat="server" OnDayRender="checkin_DayRender" ></asp:Calendar>
<br /><br />
<big>Check out:</big> <asp:Calendar ID="checkout" runat="server" OnDayRender="checkout_DayRender1" ></asp:Calendar>
<br /><br />
<big>Number of room:</big> <asp:TextBox ID="rooms" runat="server" ForeColor="black" placeholder="Number of rooms" type="number" min="1" max="2"></asp:TextBox>
<br /><br />
<big>Number of members per room:</big> <asp:TextBox ID="members" runat="server" ForeColor="black" placeholder="Number of members" type="number" min="1" max="4"></asp:TextBox>
<br /> <br />
<asp:Button ID="book" runat="server" Text="Book" ForeColor="Black" Width="200px" Height="30px" OnClick="book_Click"></asp:Button>
</div>
<div class="cleaner"> </div>
</div> <!-- end of booking -->
<div class="cleaner_h30"> </div>
<div class="cleaner_horizontal_divider_01"> </div>
<div class="cleaner_h30"> </div>
<div class="content_left_section">
<div class="content_title_01">Contact Details</div>
<div class="news_title">Address</div>
<p>The Taj Mahal Palace<br />Apollo Bunder, Near Gateway Of India, Colaba , Mumbai , Maharashtra , India<br />Pincode- 400001</p>
<div class="cleaner_h30"> </div>
<div class="news_title">Phone</div>
<p>022 6665 3366 </p>
<div class="cleaner_h20"> </div>
<div class="news_title">Email Support</div>
<p>reservations#tajhotels.com</p>
</div> <!-- end of news section -->
<div class="cleaner_h30"> </div>
<div class="cleaner_horizontal_divider_01"> </div>
<div class="cleaner_h30"> </div>
<div class="cleaner_h30"> </div>
</div> <!-- end of content left -->
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div id="content_right">
<div class="content_right_section">
<div class="content_title_01">Welcome to The <asp:Label ID="lblhotelname" runat="server" Text='<%#Eval("hotel_name") %>'></asp:Label> </div>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("ImagePath") %>' Height="200px" width="200px"/>
<p><%#Eval("d_desc") %>. </p>
</div>
<div class="cleaner_h40"> </div>
<div class="content_right_2column_box">
<div class="content_title_01">Hotel Facilities</div>
<p> <%#Eval("hotel_facilties") %></p>
</div>
<div class="content_right_2column_box">
<div class="content_title_01">Policies</div>
<ul>
<asp:Label ID="lblpolicies" runat="server" Text='<%#Eval("hotel_policies") %>'></asp:Label>
</ul>
<div class="cleaner_h10"> </div>
</div>
<div class="cleaner_h40"> </div>
<div class="content_right_section">
<div class="content_title_01">Hotel location</div>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("hotel_location") %>'></asp:Label>
<div class="cleaner_h20"> </div>
<div class="cleaner"> </div>
</div>
<div class="content_right_section">
<div class="content_title_01">Hotel price per room</div>
<asp:FormView ID="FormView1" runat="server"></asp:FormView>
<asp:Label ID="lblhotelprice" runat="server" Text='<%#Eval("price")%>'></asp:Label>
<div class="cleaner_h20"> </div>
<div class="cleaner"> </div>
</div>
<div class="cleaner_h20"> </div>
</div> <!-- end of content right -->
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</asp:Content>
.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace Hotel_Mangement
{
public partial class hotels_main : System.Web.UI.Page
{
int id;
int t1main, t2main, totalmain;
public static List<DateTime> list = new List<DateTime>();
SqlConnection con = new SqlConnection(#"Data Source=RISHIK\SQLEXPRESS;Initial Catalog=Register;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] == null)
{
Response.Redirect("hotels.aspx");
}
else
{
id = Convert.ToInt32(Request.QueryString["id"].ToString());
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from hotels_main where hotel_id=" + id + "";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
con.Close();
}
}
protected void checkin_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Red;
e.Cell.Font.Strikeout = true;
}
Session["checkinmain"] = list;
}
protected void checkout_DayRender1(object sender, DayRenderEventArgs e)
{
if ((e.Day.Date < DateTime.Now.Date) || (e.Day.Date < checkin.SelectedDate))
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Red;
e.Cell.Font.Strikeout = true;
}
Session["checkoutmain"] = list;
}
protected void book_Click(object sender, EventArgs e)
{
if (Session["USER_ID"] == null)
{
Response.Redirect("login.aspx");
}
else
{
TextBox rooms = (TextBox)FindControl("rooms");
Session["roomsmain"] = rooms.Text;
TextBox members = (TextBox)FindControl("members");
Session["membersmain"] = members.Text;
Label lblhotelprice = (Label)FindControl("lblhotelprice");
Session["initialprice"] = lblhotelprice.Text;
t1main = Convert.ToInt32(Session["roomsmain"].ToString());
t2main = Convert.ToInt32(Session["initialprice"].ToString());
totalmain = t1main * t2main;
Session["totalpricemain"] = totalmain;
con.Open();
string insertQuery = "insert into hotel_booking_details(username,hotel_name,hotel_location,check_in,check_out,members,rooms,initial_price,total_price) values('" + Session["USER_ID"].ToString() + "','" + Session["hotel_name"].ToString() + "','" + Session["hotel_location"].ToString() + "','" + Session["checkinmain"].ToString() + "','" + Session["checkoutmain"].ToString() + "','" + Session["membersmain"].ToString() + "','" + Session["roomsmain"].ToString() + "','" + Session["initialprice"].ToString() + "','" + Session["totalpricemain"].ToString() + "')";
SqlCommand cmd1 = new SqlCommand(insertQuery, con);
cmd1.ExecuteNonQuery();
con.Close();
Response.Redirect("pay.aspx");
}
}
}
}
First of all, you cannot use another form tag in ASP.Net. You will need to remove <form id="form1" >.
it gives me an null pointer exception, I am using FindControl function
from my c# backend.
TextBox rooms = (TextBox)FindControl("rooms");
About code tries to find rooms textbox inside Page control. rooms control is not a direct child of Page control.
You will need to the find control recursively. Here is the helper method -
public static Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
return root;
return root.Controls.Cast<Control>()
.Select(c => FindControlRecursive(c, id))
.FirstOrDefault(c => c != null);
}
Usage
TextBox rooms = (TextBox)FindControlRecursive(Page, "rooms");

Control 'MainContent_forenameTxt' of type 'TextBox' must be placed inside a form tag with runat=server

Control 'MainContent_forenameTxt' of type 'TextBox' must be placed inside a form tag with runat=server. [And similar errors]
This error has been bugging me for a few days now. I've narrowed the problem down to an issue being within my Master Page.
For some reason, ASP TextBoxes, Buttons etc.. require to be in a form (Which shouldn't necessarily be the case) however my Program decided that it wants to be.
So, this issue began when I placed the forms in, stating I could only have one with a runat="server". After much googling and questioning I was given this piece of code:
public override void VerifyRenderingInServerForm(Control Control)
{
//base.VerifyRenderingInServerForm(Control);
}
Which, from what I can see, does absolutely nothing. It never gets called, and has nothing in it, however makes the page display - so I have absolutely no idea what it does.
So continuing on, it began to bug me, then I realised that my Buttons weren't actually doing anything, except 'refreshing' the page essentially. (Refer to near the bottom of page, with the onClicks
<%# Page Title="Registration" Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.Master" CodeFile="registration.aspx.cs" Inherits="registration" %>
<div class="contact-bg2">
<div class="container">
<div class="booking">
<h3>Register</h3>
<p>
</p>
<div class="col-md-8 booking-form">
<h5>Forename</h5>
<asp:TextBox ID="forenameTxt" runat="server"></asp:TextBox>
<h5>Surname</h5>
<asp:TextBox ID="surnameTxt" runat="server"></asp:TextBox>
<h5>Telephone</h5>
<asp:TextBox ID="telephoneTxt" runat="server"></asp:TextBox>
<h5>Mobile</h5>
<asp:TextBox ID="mobileTxt" runat="server"></asp:TextBox>
<h5>Address</h5>
<asp:TextBox ID="addressLn1Txt" placeholder="Line 1" runat="server"></asp:TextBox>
<asp:TextBox ID="addressLn2Txt" placeholder="Line 2" runat="server"></asp:TextBox>
<asp:TextBox ID="addressLn3Txt" runat="server" placeholder="Line 3"></asp:TextBox>
<h5>Postal Code</h5>
<asp:TextBox ID="postalTxt" runat="server"></asp:TextBox>
<h5>Username</h5>
<asp:TextBox ID="registerUsernameTxtbox" runat="server"></asp:TextBox>
<h5>Password Confirm Password</h5>
<asp:TextBox ID="registerPasswordTxtbox" runat="server" type="password"></asp:TextBox>
<asp:TextBox ID="passwordConfirmTxt" runat="server" type="password"></asp:TextBox>
<h5></h5>
<asp:Button ID="submitBtn" runat="server" Text="SUBMIT" OnClick="submitBtn_Click" />
<asp:Button ID="resetBtn" runat="server" Text="RESET" OnClick="resetBtn_Click" />
</div>
</div>
</div>
</asp:Content>
Code Behind:
protected void submitBtn_Click(object sender, EventArgs e)
{
//If there is any blank fields, these if statements will be run.
try
{
//If the fields entered have all had an input, this if statement will submit it to the database.
if (forenameTxt.Text != "" && surnameTxt.Text != "" && telephoneTxt.Text != "" && addressLn1Txt.Text != "" && addressLn2Txt.Text != "" && postalTxt.Text != "" && registerUsernameTxtbox.Text != "" && registerPasswordTxtbox.Text != "" && passwordConfirmTxt.Text != "")
{
DLQueries reposit = new DLQueries();
//Refers to 'addCustomerAccount' in droversLodgeRepository
reposit.addCustomerAccount(registerUsernameTxtbox.Text.ToString(),
registerPasswordTxtbox.Text.ToString(), forenameTxt.Text.ToString(),
surnameTxt.Text.ToString(), mobileTxt.Text.ToString(), telephoneTxt.Text.ToString(),
addressLn1Txt.Text.ToString(), addressLn2Txt.Text.ToString(),
addressLn3Txt.Text.ToString(), postalTxt.Text.ToString());
//Redirects to homepage
}
else
{
Response.Redirect("homepage.aspx");
}
}
catch (Exception)
{
}
}
protected void resetBtn_Click(object sender, EventArgs e)
{
forenameTxt.Text = "";
surnameTxt.Text = "";
telephoneTxt.Text = "";
addressLn1Txt.Text = "";
addressLn2Txt.Text = "";
postalTxt.Text = "";
registerUsernameTxtbox.Text = "";
registerPasswordTxtbox.Text = "";
passwordConfirmTxt.Text = "";
}
Now from that alone, I never saw any issues (unless someone else can see any).
So now, I assumed that the issue is on the masterpage. I've went through the masterpage, comparing it with an old website I built and couldn't find the issue.
Head:
<head id="Head1" runat="server">
<title>Page.Title</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Pinyon+Script' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Quicksand:400,700' rel='stylesheet' type='text/css'>
<link href="css/bootstrap.css" rel='stylesheet' type='text/css'/>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery.min.js"></script>
</head>
Body:
<body>
<div class="header">
<div class="top-header">
<div class="container">
<div class="logo">
<img src="images/logo.png"/>
</div>
<span class="menu"> </span>
<div class="m-clear"></div>
<div class="top-menu">
<ul>
<li class="scroll">HOME</li>
<li><a class="scroll" href="facilities.aspx">FACILITIES</a></li>
<li><a class="scroll" href="pricing.aspx">PRICS</a></li>
<li><a class="scroll" href="contactUs.aspx">CONTACT US</a></li>
</ul>
<script>
$("span.menu").click(function () {
$(".top-menu ul").slideToggle(200);
});
</script>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<div id="body">
<asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
<section class="content-wrapper main-content clear-fix">
<asp:ContentPlaceHolder runat="server" ID="MainContent" >
</asp:ContentPlaceHolder>
</section>
</div>
</>
<!---->
<div class="fotter">
<div class="container">
<h3>143 City Located Hotels World Wide</h3>
<h4>"Hospitality, Quality & Good Locations. We only provide you with the best hotels" - John Deo</h4>
<i class="man"></i>
</div>
</div>
<!---->
<div class="fotter-info">
<div class="container">
<div class="col-md-5 details">
<div class="hotel-info">
<h4>ABOUT THIS HOTEL</h4>
<p>This hotel is a 4 Star Hotel found on the Isle of Mull, in Scotland. </p>
<p><b>In order to book for this hotel, you will require to create an account online!</b></p>
</div>
<div class="news">
<h4>LATEST NEWS</h4>
<h5>Grand Hotel Joins DeluxelHotels</h5>
15 AUG
<h5>Happy Chirstmas To Everyone</h5>
15 AUG
<h5>Best Places To Visit 2014</h5>
15 AUG
<h5>Various Offers</h5>
15 AUG
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-7 details">
<div class="join">
<h4>JOIN DELUXEHOTELS</h4>
<p>
TBA
</p>
<p>TBA</p>
READ MORE
</div>
<div class="member">
<h4>MEMBERS AREA</h4>
<form id="Form1" runat="server">
<p>Username</p>
<asp:textbox id="txtUsername" runat="server"></asp:textbox>
<p>Password</p>
<asp:textbox id="txtPassword" textmode="Password" runat="server" />
<asp:button id="logoutBtn" runat="server" text="LOGOUT" visible="false" onclick="logoutBtn_Click" />
<asp:button id="loginBtn" runat="server" text="LOGIN" onclick="loginBtn_Click" />
<asp:button id="registerBtn" runat="server" text="REGISTER" onclick="registerBtn_Click" />
</form>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
</div>
</body>
Now just to add on as a side-note.
I'm currently using a BootStrap UI Template for my website. I've took highlights of pieces of code which would/could be causing the problem
Things that I have noticed/tried:
- Buttons on MasterPage work fine.
- Buttons on 'registration' page don't work (i.e reset and submit)
- The parameter on the registration page was too big, so placed all details in that method instead
- MasterPage MainContent - Placing a Form within this.
- Removing all forms
- Create a new testpage which doesn't use MasterPage (buttons do work)
- Compared with my other website
I'm no expert at fixing issues, and have struggled to find this error, which you'll most likely find much more quickly than myself.
I'd like to apologise for such a large issue/question, but I'd like to get this sorted and not repeat my problem again in the future.
Thanks for looking at this.
I never found the issue. However, I found a workaround until I can find a sufficient alternative.
I started a new Project in Visual Studio, and decided to pick out every piece of information which would be an absolute necessity for the Website to still look relatively decent, and work.
[This means, I have one form over a contentplaceholder, which is holding everything, including another contentplaceholder where the information from every other page is in that placeholder].
I am still getting a few of the errors (which are easily fixable), however the override class is now, not being used due to some debugging finds, I found that it was overriding the button onClicks.

fileupload's upload button works different in IE and Chrome

For those who worked with bootstrap, knows it does not support input type = file, so I hide the asp:fileupload using jQuery (after document ready), and have and for the solution (as you can see from the code
<script type="text/javascript">
$(document).ready(function ()
{
$('#columnSelect').change(function ()
{
getImportColumnOrder();
});
// change file upload style similiar to bootstrap style
//$('#uploader').hide();
$('#uploader').change(function ()
{
var val = $(this).val();
var file = val.split(/[\\/]/);
$('#file').val(file[file.length - 1]);
});
});
function getImportColumnOrder()
{
var order = '';
$('#selectOrer').val('');
$('select', $('#MappingTable')).each(function ()
{
order += $(this).prop('selectedIndex') + ',';
});
$('#selectOrder').val(order.substr(0, order.length - 1));
}
</script>
<div class="span12">
<asp:DropDownList ID="ddl_DBTableList" runat="server" CssClass="combobox" Style="display: inline">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Import_Test">Import_Test</asp:ListItem>
</asp:DropDownList>
<asp:FileUpload ID="uploader" runat="server" CssClass="btn" />
<div class="input-append" style="display: inline;">
<input id="file" class="input-medium" type="text" />
<a class="btn" onclick="$('input[id=uploader]').click();">Select File</a>
</div>
<p />
<div>
<asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" />
</div>
<p />
<asp:Label ID="result" runat="server" ForeColor="Red"></asp:Label>
<p />
<asp:Label ID="data" runat="server" BackColor="#CCCCCC"></asp:Label>
<p />
<asp:Button ID="btn_import" runat="server" Text="Next" OnClick="doImport" OnClientClick="getImportColumnOrder();return true;" Visible="false" CssClass="btn btn-success" />
</div>
Steps are click on the "Select File", a file chooser popped up for file selection. After double clicked a file, the file location gets displayed in , and also the asp fileupload control.
In Chrome and FF, when I clicked btn_uplaod (button), it runs as supposed. In IE, it will clear the fileupload's content and does nothing (a client side action) and will not do any postback.
If this is a program problem, then maybe Chrome and FF will not run correctly. I'm suspecting is there anything that I need to add to make IE run as suppose to?
image after click upload (IE), (Browse link is cleared)
image after click upload (Chrome), (Run as supposed to)
thanks!
I've made a simple version for those of you who wants to try on Visual studio:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="postback_problem.aspx.cs" Inherits="postback_problem" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="uploader" runat="server" CssClass="btn" /> <div> <input id="file" class="input-medium" type="text" /> <a onclick="$('input[id=uploader]').click();">Select File</a> </div> <p /> <div> <asp:Button ID="btn_uplaod" runat="server" OnClick="doUpload" Text="Upload" CssClass="btn" /> </div> <asp:Label ID="result" runat="server"></asp:Label> </div> </form> </body> </html>
and
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class postback_problem : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void doUpload(object sender, EventArgs e) { result.Text = "no problem!"; } }

Updating the master page when the control is within an update panel on the content page

I have an application which has a control within a update panel but needs to update a part of the master page aswel - i m not sure if this can be done?
The
<asp:ScriptManager ID="ScriptManager" runat="server" />
is within the master page
and the part of the master page i want to update is the following:
<div id="divPanelMyCover" class="divPanelMyCover" runat="server">
<div class="sectionYourProtection">
<div class="sectionPadding">
<h4>Title</h4>
</div>
<div class="innerPanelMyCover">
<br/>
<ul class="bulletList" type="square">
<li><span class="spBold">Monthly Payment: </span><asp:Label ID="lblMonthlyPayment" runat="server" Text=""></asp:Label </div>
</div>
</div>
code behind:
lblMonthlyPayment.Text = Convert.ToString(application.Premium);
The lblMonthlyPayment needs to change depending on what the user selects on a content page but as the control is within an update panel it is not working.
Content page:
<asp:UpdatePanel ID="upUpSell" runat="server">
<ContentTemplate>
<div id ="divSlider" runat="server" visible="false">
<br />
<h3>If you want, you can change the amount ... </h3>
<hr />
<div class="sliderContainer">
<telerik:RadSlider id ="rdSlider" AutoPostBack="true" runat="server" Orientation="Horizontal" Width="450"
Height="70" MinimumValue="0" MaximumValue="50" LargeChange="10" TrackPosition="BottomRight"
ItemType="Tick" IsSelectionRangeEnabled="false" SelectionStart="10" SelectionEnd="30" Skin="Default" DragText="Select Premium" >
</telerik:RadSlider>
</div>
<asp:Label ID="lblValue" runat="server" Text="" Visible="false"></asp:Label>
</div>
c#
protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
//Pre-populate the screen with data from ApplicationBO
ApplicationBO application = (ApplicationBO)Session["Application"];
if (!Page.IsPostBack)
{
if (Session["Application"] == null)
application = new ApplicationBO();
else
application = (ApplicationBO)Session["Application"];
lblclientName.Text = application.FirstName;
rdSlider.Value = Convert.ToDecimal(application.Premium);
lblMonthlyPayment.Text = Convert.ToString(application.Premium);
}
divSlider.Visible = true;
string upsellValue = Convert.ToString(application.Premium);
if (divSlider.Visible == true)
{
upsellValue = Convert.ToString(rdSlider.Value);
// Save the current page information
application.Premium = Convert.ToDecimal(upsellValue);
}
Thanks in advance...
Wrap the label with an UpdatePanel with UpdateMode="Always"

Categories