tryin todo a work around so user types something within textbox can this be done on this page ?
this box basically passes value to another page but the way its been designed is a bit tricky for me
if so were (remember im only learning)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class ProfilePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var user = UserObject.CurrentUser;
int i = 0;
StringBuilder sBuilder = new StringBuilder();
sBuilder.Append("<tr>");
foreach (var prop in user.GetType().GetProperties().Where(x => x.CanRead && x.CanWrite))
{
if (i % 2 == 0 && i != 0)
sBuilder.Append("</tr><tr>");
sBuilder.AppendFormat("<td><b>{0}</b></td><td>{1}</td>", prop.Name, prop.GetValue(user, null).ToString());
i++;
}
Literal l = new Literal();
l.Text = sBuilder.ToString();
plhProps.Controls.Add(l);
/// <summary>
/// Selects a drop down value if the passed in value exists in the items list of the drop down list
/// </summary>
/// <param name="List">The drop down list</param>
/// <param name="Value">The value to set</param>
private void SelectDropDownValueIfExists(DropDownList List, string Value)
{
if (List.Items.OfType<ListItem>().Count(x => x.Value.Equals(Value, StringComparison.InvariantCultureIgnoreCase)) > 0)
List.SelectedValue = Value;
}
/// <summary>
/// Gets a value from the drop down list. Will return blank if the value is -1
/// </summary>
/// <param name="List">The drop downlist</param>
/// <returns></returns>
private string GetDropDownValue(DropDownList List)
{
return GetDropDownValue(List, "-1");
}
/// <summary>
/// Gets a value from the drop down list. Will return blank if the value equals the defaultIgnorevalue (case insensitive)
/// </summary>
/// <param name="List">The drop down list</param>
/// <param name="DefaultIgnoreValue">The default ignore value</param>
/// <returns></returns>
private string GetDropDownValue(DropDownList List, string DefaultIgnoreValue)
{
return List.SelectedValue.Equals(DefaultIgnoreValue, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : List.SelectedValue;
}
if (fupImage.HasFile)
{
if (!UserHelper.UploadImage(UserObject.CurrentUser.Username, this.fupImage.PostedFile))
{
this.Label1.Text = "There was an error while uploading your profile image. Please try again.";
return;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// Summary description for UserObject
/// </summary>
public class UserObject
{
/// <summary>
/// Retrieves the current user
/// </summary>
/// <remarks>
/// This static method will return the currently authenticated user in the form of Userobject.
/// The userobject will be created once during the execution of the page (and sub methods) and will be stored
/// in the current HttpContext. if the HttpContext is not available the Userobject will be null
/// </remarks>
public static UserObject CurrentUser
{
get
{
if (HttpContext.Current == null)
return new UserObject();
var ctx = HttpContext.Current;
if (!ctx.User.Identity.IsAuthenticated)
return new UserObject();
else if (ctx.Items["_userCache"] != null)
if (ctx.Items["_userCache"] is UserObject)
return (UserObject)ctx.Items["_userCache"];
return (UserObject)(ctx.Items["_userCache"] = new UserObject(ctx.User.Identity.Name));
}
}
public UserObject()
{
}
public UserObject(string Username)
{
this.Username = Username;
if (LoginHelper.ProfileCreated(Username))
UserHelper.LoadProfile(this);
}
public void Save()
{
UserHelper.SaveProfile(this);
}
public string Username { get; set; }
[ProfileData("Male")]
public string Gender { get; set; }
[ProfileData("")]
public string HairColor { get; set; }
[ProfileData("")]
public string EyeColor { get; set; }
[ProfileData("")]
public string Height { get; set; }
[ProfileData("")]
public string Weight { get; set; }
[ProfileData("")]
public string Religion { get; set; }
[ProfileData("")]
public string MaritalStatus { get; set; }
[ProfileData("")]
public string NoOfChildren { get; set; }
[ProfileData("")]
public string DoYouWantChildren { get; set; }
[ProfileData("")]
public string DoYouSmoke { get; set; }
[ProfileData("")]
public string DoYouDrink { get; set; }
[ProfileData("")]
public string DoYouTakeDrugs { get; set; }
[ProfileData("")]
public string DoYouDrive { get; set; }
[ProfileData("")]
public string DoYouHavePets { get; set; }
[ProfileData("")]
public string LongestRelationship { get; set; }
[ProfileData("")]
public string IAmLookingFor { get; set; }
[ProfileData("")]
public string WouldYouDateASmoker { get; set; }
[ProfileData("")]
public string WouldYouDatePersonWithChildren { get; set; }
}
richkyrs
Member
436 Points
500 Posts
ho can i pace a txtbo string wit in this page
Apr 27, 2012 09:59 PM|LINK
tryin todo a work around so user types something within textbox can this be done on this page ?
this box basically passes value to another page but the way its been designed is a bit tricky for me
if so were (remember im only learning)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
public partial class ProfilePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var user = UserObject.CurrentUser;
int i = 0;
StringBuilder sBuilder = new StringBuilder();
sBuilder.Append("<tr>");
foreach (var prop in user.GetType().GetProperties().Where(x => x.CanRead && x.CanWrite))
{
if (i % 2 == 0 && i != 0)
sBuilder.Append("</tr><tr>");
sBuilder.AppendFormat("<td><b>{0}</b></td><td>{1}</td>", prop.Name, prop.GetValue(user, null).ToString());
i++;
}
Literal l = new Literal();
l.Text = sBuilder.ToString();
plhProps.Controls.Add(l);
this.imgProfile.ImageUrl = string.Format("ImageHandler.ashx?UserName={0}", user.Username);
}
}
richkyrs
Member
436 Points
500 Posts
Re: ho can i pace a txtbo string wit in this page
Apr 27, 2012 10:04 PM|LINK
or is this page it gets placed in?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class CreateUser : System.Web.UI.Page
{
string[] Extensions = new string[] { ".gif", ".jpg", ".jpeg", ".png" };
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var profCreated = LoginHelper.ProfileCreated(UserObject.CurrentUser.Username);
this.ltrHeader.Text = profCreated ? "Edit \\ Update" : "Create";
this.Button1.Text = profCreated ? "Update Profile" : "Create Profile";
var userObject = UserObject.CurrentUser;
SelectDropDownValueIfExists(this.ddlDateSmoker, userObject.WouldYouDateASmoker);
SelectDropDownValueIfExists(this.ddlDateWithChildren, userObject.WouldYouDatePersonWithChildren);
SelectDropDownValueIfExists(this.ddlDoHavePets, userObject.DoYouHavePets);
SelectDropDownValueIfExists(this.ddlDoYouDrink, userObject.DoYouDrink);
SelectDropDownValueIfExists(this.ddlDoYouDrive, userObject.DoYouDrive);
SelectDropDownValueIfExists(this.ddlDoYouSmoke, userObject.DoYouSmoke);
SelectDropDownValueIfExists(this.ddlDoYouTakeDrugs, userObject.DoYouTakeDrugs);
SelectDropDownValueIfExists(this.ddlDoYouWantChildren, userObject.DoYouWantChildren);
SelectDropDownValueIfExists(this.ddlEyeColor, userObject.EyeColor);
SelectDropDownValueIfExists(this.ddlGender, userObject.Gender);
SelectDropDownValueIfExists(this.ddlHairColor, userObject.HairColor);
SelectDropDownValueIfExists(this.ddlHeight, userObject.Height);
SelectDropDownValueIfExists(this.ddlIAmLookingFor, userObject.IAmLookingFor);
SelectDropDownValueIfExists(this.ddlLongestRelationShip, userObject.LongestRelationship);
SelectDropDownValueIfExists(this.ddlMaritalStatus, userObject.MaritalStatus);
SelectDropDownValueIfExists(this.ddlNoOfChildren, userObject.NoOfChildren);
SelectDropDownValueIfExists(this.ddlReligion, userObject.Religion);
SelectDropDownValueIfExists(this.ddlWeight, userObject.Weight);
}
}
/// <summary>
/// Selects a drop down value if the passed in value exists in the items list of the drop down list
/// </summary>
/// <param name="List">The drop down list</param>
/// <param name="Value">The value to set</param>
private void SelectDropDownValueIfExists(DropDownList List, string Value)
{
if (List.Items.OfType<ListItem>().Count(x => x.Value.Equals(Value, StringComparison.InvariantCultureIgnoreCase)) > 0)
List.SelectedValue = Value;
}
/// <summary>
/// Gets a value from the drop down list. Will return blank if the value is -1
/// </summary>
/// <param name="List">The drop downlist</param>
/// <returns></returns>
private string GetDropDownValue(DropDownList List)
{
return GetDropDownValue(List, "-1");
}
/// <summary>
/// Gets a value from the drop down list. Will return blank if the value equals the defaultIgnorevalue (case insensitive)
/// </summary>
/// <param name="List">The drop down list</param>
/// <param name="DefaultIgnoreValue">The default ignore value</param>
/// <returns></returns>
private string GetDropDownValue(DropDownList List, string DefaultIgnoreValue)
{
return List.SelectedValue.Equals(DefaultIgnoreValue, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : List.SelectedValue;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
this.Label1.Text = string.Empty;
if (fupImage.HasFile)
{
if (!this.Extensions.Any(x => x.Equals(System.IO.Path.GetExtension(this.fupImage.PostedFile.FileName), StringComparison.InvariantCultureIgnoreCase)))
{
this.Label1.Text = "Invalid image file type, the expected file types are, " + string.Join(", ", this.Extensions);
return;
}
}
var userObject = UserObject.CurrentUser;
userObject.DoYouDrive = GetDropDownValue(this.ddlDoYouDrive);
userObject.DoYouHavePets = GetDropDownValue(this.ddlDoHavePets);
userObject.DoYouDrink = GetDropDownValue(this.ddlDoYouDrink);
userObject.DoYouSmoke = GetDropDownValue(this.ddlDoYouSmoke);
userObject.DoYouTakeDrugs = GetDropDownValue(this.ddlDoYouTakeDrugs);
userObject.DoYouWantChildren = GetDropDownValue(this.ddlDoYouWantChildren);
userObject.Gender = GetDropDownValue(this.ddlGender);
userObject.HairColor = GetDropDownValue(this.ddlHairColor);
userObject.EyeColor = GetDropDownValue(this.ddlEyeColor);
userObject.Height = GetDropDownValue(this.ddlHeight);
userObject.IAmLookingFor = GetDropDownValue(this.ddlIAmLookingFor);
userObject.LongestRelationship = GetDropDownValue(this.ddlLongestRelationShip);
userObject.MaritalStatus = GetDropDownValue(this.ddlMaritalStatus);
userObject.NoOfChildren = GetDropDownValue(this.ddlNoOfChildren);
userObject.Religion = GetDropDownValue(this.ddlReligion);
userObject.Weight = GetDropDownValue(this.ddlWeight);
userObject.WouldYouDateASmoker = GetDropDownValue(this.ddlDateSmoker);
userObject.WouldYouDatePersonWithChildren = GetDropDownValue(this.ddlDateWithChildren);
userObject.Save();
if (fupImage.HasFile)
{
if (!UserHelper.UploadImage(UserObject.CurrentUser.Username, this.fupImage.PostedFile))
{
this.Label1.Text = "There was an error while uploading your profile image. Please try again.";
return;
}
}
Response.Redirect("ProfilePage.aspx");
}
}
richkyrs
Member
436 Points
500 Posts
Re: ho can i pace a txtbo string wit in this page
Apr 27, 2012 10:06 PM|LINK
or is it this page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// Summary description for UserObject
/// </summary>
public class UserObject
{
/// <summary>
/// Retrieves the current user
/// </summary>
/// <remarks>
/// This static method will return the currently authenticated user in the form of Userobject.
/// The userobject will be created once during the execution of the page (and sub methods) and will be stored
/// in the current HttpContext. if the HttpContext is not available the Userobject will be null
/// </remarks>
public static UserObject CurrentUser
{
get
{
if (HttpContext.Current == null)
return new UserObject();
var ctx = HttpContext.Current;
if (!ctx.User.Identity.IsAuthenticated)
return new UserObject();
else if (ctx.Items["_userCache"] != null)
if (ctx.Items["_userCache"] is UserObject)
return (UserObject)ctx.Items["_userCache"];
return (UserObject)(ctx.Items["_userCache"] = new UserObject(ctx.User.Identity.Name));
}
}
public UserObject()
{
}
public UserObject(string Username)
{
this.Username = Username;
if (LoginHelper.ProfileCreated(Username))
UserHelper.LoadProfile(this);
}
public void Save()
{
UserHelper.SaveProfile(this);
}
public string Username { get; set; }
[ProfileData("Male")]
public string Gender { get; set; }
[ProfileData("")]
public string HairColor { get; set; }
[ProfileData("")]
public string EyeColor { get; set; }
[ProfileData("")]
public string Height { get; set; }
[ProfileData("")]
public string Weight { get; set; }
[ProfileData("")]
public string Religion { get; set; }
[ProfileData("")]
public string MaritalStatus { get; set; }
[ProfileData("")]
public string NoOfChildren { get; set; }
[ProfileData("")]
public string DoYouWantChildren { get; set; }
[ProfileData("")]
public string DoYouSmoke { get; set; }
[ProfileData("")]
public string DoYouDrink { get; set; }
[ProfileData("")]
public string DoYouTakeDrugs { get; set; }
[ProfileData("")]
public string DoYouDrive { get; set; }
[ProfileData("")]
public string DoYouHavePets { get; set; }
[ProfileData("")]
public string LongestRelationship { get; set; }
[ProfileData("")]
public string IAmLookingFor { get; set; }
[ProfileData("")]
public string WouldYouDateASmoker { get; set; }
[ProfileData("")]
public string WouldYouDatePersonWithChildren { get; set; }
}
richkyrs
Member
436 Points
500 Posts
Re: ho can i pace a txtbo string wit in this page
Apr 27, 2012 11:06 PM|LINK
sometime the day will be helpful
FightAsABull
Contributor
2228 Points
424 Posts
Re: ho can i pace a txtbo string wit in this page
Apr 30, 2012 05:47 AM|LINK
Hi, what's the issue?