Javascript和查询字符串问题
本文关键字:问题 字符串 查询 Javascript | 更新日期: 2023-09-27 18:18:47
每当我在查询字符串中传递变量时,一些java脚本不显示。只有当url看起来像这样时才会发生。default.aspx?yesId=1&noId=27如果只是默认值。Aspx的Java脚本显示良好。
你知道为什么吗?或者如何修复它?有没有其他方法来显示这个javascript代码?
违约。不显示的代码在底部Div标签"ads"
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="Direction">
<asp:Label ID="Label1" runat="server" Text="Click on the girl you like better." Font-Size="Large"
Width="270" Font-Bold="True" ForeColor="#1B0358"></asp:Label>
</div>
<div id="pictures">
<div id="ratedpic">
<p>
<asp:HyperLink ID="HyperLink1" runat="server">
<asp:Label ID="RatedPicnameLabel" runat="server" Text="" Font-Size="Medium"></asp:Label></asp:HyperLink>
</p>
<asp:ImageButton ID="RatedImage" Width="70%" runat="server" /><br />
<asp:Label ID="RatedPicRating" runat="server" Text=""></asp:Label><br />
</div>
<div id="MainPics">
<div id="RightPic">
<p>
<asp:Label ID="FirstPicMemberNameLabel" runat="server" Text="" Font-Bold="True" ForeColor="White"></asp:Label>
</p>
<asp:ImageButton ID="FirstPicLink" Width="90%" runat="server" OnClick="FirstPicLink_Click" />
</div>
<div id="LeftPic">
<p>
<asp:Label ID="SecondPicMemberNameLabel" runat="server" Text="" ForeColor="White"
Font-Bold="True"></asp:Label>
</p>
<asp:ImageButton ID="SecondPicLink" Width="90%" runat="server" OnClick="SecondPicLink_Click" />
</div>
<div id="skip">
<asp:LinkButton ID="LBNoChoice" PostBackUrl="~/default.aspx" ForeColor="White" runat="server">Skip - I Can't Choose</asp:LinkButton>
</div>
</div>
</div>
<div id="Ads">
<script type="text/javascript">
google_ad_client = "ca-pub-**MyPubCode**";
google_ad_slot = "**AdCode**";
google_ad_width = 728;
google_ad_height = 90;
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
代码隐藏页
protected void Page_Load(object sender, EventArgs e)
{
//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"]);
RatedImage.Visible = true;
HyperLink1.Visible = true;
RatedPicRating.Visible = true;
//pass ratings
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);
//Percentage = Convert.ToUInt32(Percentage);
//TotalyesVotes.Text = Percentage.ToString();
//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;
}
//RatedImage.Enabled = false;
//Get
}
else
{
RatedImage.Visible = false;
HyperLink1.Visible = false;
RatedPicRating.Visible = false;
}
Picture dlPicture = new Picture();
DataTable DTPictures = dlPicture.GetRandomPicture();
Picture dlPicture2 = new Picture();
DataTable DTPictures2 = dlPicture2.GetRandomPicture();
// the variables to hold the yes and no Id's for each set
string firstNoPicId = "";
string firstYesPicId = "";
string secondNoPicId = "";
string secondYesPicId = "";
foreach (DataRow row in DTPictures.Rows)
{
firstYesPicId = row["PicID"].ToString();
secondNoPicId = firstYesPicId;
FirstPicMemberNameLabel.Text = row["MemberName"].ToString();
FirstPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
foreach (DataRow row in DTPictures2.Rows)
{
secondYesPicId = row["PicID"].ToString();
firstNoPicId = secondYesPicId;
SecondPicMemberNameLabel.Text = row["MemberName"].ToString();
SecondPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
while (firstYesPicId == secondYesPicId)
{
DTPictures2 = dlPicture2.GetRandomPicture();
foreach (DataRow row in DTPictures2.Rows)
{
secondYesPicId = row["PicID"].ToString();
firstNoPicId = secondYesPicId;
SecondPicMemberNameLabel.Text = row["MemberName"].ToString();
SecondPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
}
FirstPicLink.PostBackUrl = "default.aspx?yesId=" + firstYesPicId + "&"+"noId=" + firstNoPicId;
SecondPicLink.PostBackUrl = "default.aspx?yesId=" + secondYesPicId + "&"+"noId=" + secondNoPicId;
}
您是否可以创建这样的东西并测试请求/响应
HttpRequest q = Request;
string v = q.QueryString["yesId"]
if (v != null)
{
}
v = q.QueryString["noId"];
if (v != null)
{
}