JavaScript 和查询字符串问题
当我在查询字符串中传递变量时,一些java脚本不会显示。 只有当 url 看起来像这样时才会发生。default.aspx?yesId=1&noId=27 如果它只是 default.aspx,java 脚本显示得很好。
你知道为什么吗?或者如何解决?有没有其他方法来显示这段 javascript 代码?
Default.aspx 不显示的代码位于底部 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;
}
When ever I pass variables in my Query string some java script does not show up.
It only happens when the url looks like this.. default.aspx?yesId=1&noId=27 if its just default.aspx the java script shows just fine.
Do you have any idea why? Or how to fix it? Is there another way to dis play this javascript code?
Default.aspx The code thats does not display is in the bottom Div tag "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>
Code Behind page
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能创建这样的东西并测试请求/响应吗
Could you create something like this and test the Request / Response