我想在下面更改我的代碼,以便不必使用查詢字符串。我想設置兩個變量yesID
和noID
。我正在從default.aspx
導航到同一頁面default.aspx
。這可能嗎?如果是這樣如何?將變量傳遞到沒有查詢字符串的同一頁面
//get query string
if (Request.QueryString["yesId"] != null && Request.QueryString["noId"] != null)
{
int yesPictureId = Convert.ToInt32(Request.QueryString["yesId"]);
int noPictureId = Convert.ToInt32(Request.QueryString["noId"]);
//Set rated image Items to Visible
RatedImage.Visible = true;
HyperLink1.Visible = true;
RatedPicRating.Visible = true;
//pass ratings to database
Ratings PassRatings = new Ratings();
PassRatings.InsertRatings(yesPictureId, 1);
PassRatings.InsertRatings(noPictureId, 2);
//Get total yes and nos and Do Calculation
Ratings GetNoVotes = new Ratings();
int DATotalYesVotes = GetNoVotes.GetTotalNOVotes(1, yesPictureId);
int DaTNoVotes = GetNoVotes.GetTotalNOVotes(2, yesPictureId);
int DaTotalVotes = DATotalYesVotes + DaTNoVotes;
double Percentage = ((double)DATotalYesVotes/(double)DaTotalVotes) * 100;
//Round percentage
Percentage = Math.Round(Percentage, MidpointRounding.AwayFromZero);
//Insert New percentage
Picture UpdatePictureTating = new Picture();
UpdatePictureTating.UpdateRatings(yesPictureId, (int)Percentage);
//Create pictue object
Picture RatedPic = new Picture();
DataTable DARatedPicture = RatedPic.GetRatedPicByQueryString(yesPictureId);
//Assign Location and Rating to variables
foreach (DataRow row in DARatedPicture.Rows)
{
// firstRatedPicId = row["PicID"].ToString();
//secondNoPicId = firstYesPicId;
//holds member Id for profile link
int MemberID = (int)row["MemberID"];
RatedPicnameLabel.Text = row["MemberName"].ToString() + "'s profile";
HyperLink1.NavigateUrl = "Member.aspx?UserID=" + MemberID;
RatedPicRating.Text = "Banged Rating: " + row["PicRating"].ToString() + "%";
RatedImage.ImageUrl = "Pictures/" + row["PicLoc"];
RatedImage.PostBackUrl = "Member.aspx?UserID=" + MemberID;
}
}
else
{
//If we dont have any ratied pictures hide those elements
RatedImage.Visible = false;
HyperLink1.Visible = false;
RatedPicRating.Visible = false;
}
我在下面設置變量。我不想使用查詢字符串。
FirstPicLink.PostBackUrl = "default.aspx?yesId=" + firstYesPicId + "&noId=" + firstNoPicId;
SecondPicLink.PostBackUrl = "default.aspx?yesId=" + secondYesPicId + "&noId=" + secondNoPicId;
我在想這樣的事情。但是,我如何存儲這些變量?一旦頁面重新加載,它們不會丟失。
yesID = 1
NoID = 2
FirstPicLink.PostBackUrl = "default.aspx";
SecondPicLink.PostBackUrl = "default.aspx";