2011-12-23 4 views
0

쿼리 문자열에 변수를 전달할 때 일부 Java 스크립트가 표시되지 않습니다. URL이 다음과 같이 표시 될 때만 발생합니다 .. default.aspx? yesId = 1 & noId = 27 자바 스크립트 default.aspx가 괜찮 으면 true로 표시됩니다.자바 스크립트 및 쿼리 문자열 문제

이유가 궁금하십니까? 또는 그것을 고치는 방법? 이 자바 스크립트 코드를 사용하지 않는 다른 방법이 있습니까? 페이지 뒤에

을 Default.aspx 그게 전부가 표시되지 않는 코드는 아래 사업부 태그에 "광고"

<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; 


    } 
+1

VS 내부의 리팩토링 도구를 사용하여 Page_Load()를 리팩토링하는 것도 고려해 볼 수 있습니다. 너무 많이 보이고 읽기가 힘들어서 .. 당신에게 달려 있습니다 .. 제안 사항 .. 또한 IsPostBack을 추가 할 것입니다. 포스트 백이 다시 한번 단지 제안 일 뿐이라는 것을 나타냅니다. – MethodMan

+0

어떻게 IsPostBack을 확인합니까? 그것은 무엇을 할 것인가? – CsharpBeginner

+0

페이지가 처음로드 될 때만 실행하고 포스트 백에는 실행하지 않으려는 코드가있는 경우 다음과 같은 체크 안에이를 래핑합니다. if (Page.IsPostBack) {// code goes here} –

답변

0

이 같은 것을 만들 수 및 요청/응답을 테스트하십시오.

HttpRequest q = Request; 
string v = q.QueryString["yesId"] 
    if (v != null) 
    { 
    } 
    v = q.QueryString["noId"]; 
    if (v != null) 
    { 
    } 
+0

약간 수정하고 URL에 검색어 문자열이 있으면 자바 스크립트를 계속 가져올 수있는 if 문입니다. – CsharpBeginner

+0

HttpRequest q = 요청; 문자열 v = q.QueryString [ "yesId"]; 문자열 J = q.QueryString [ "noId"]; if (v! = null && J! = null) { – CsharpBeginner

+0

멋진 점은 결과가 있는지 여부를 확인하는 데 도움이되는지 알고 싶습니다. – MethodMan