2016-12-14 4 views
0

Я занимаюсь созданием веб-приложения asp.net на C# с помощью Visual Studio.Отказоустойчивые окна ответов Response.Write не работают должным образом в веб-формах asp.net

В старом посте я спрашивал о всплывающих сообщениях в asp.net и сказал, что у веб-форм их нет. Я получил быстрое исправление, используя: Response.Write («alert (« Hello world »);) ;. Это работает достаточно хорошо, когда вы используете его только один раз в качестве подтверждения при открытии новой страницы. Проблема, с которой я столкнулась, состоит в том, что у меня есть куча операторов if в событии с нажатием кнопки, и работает только первое предупреждение о скрипте (if (poundRadBtn.Checked)). Кто-нибудь сможет объяснить мне, почему другие три не работают, и есть ли исправление или альтернатива? Заранее спасибо!

protected void submitPayBtn_Click(object sender, EventArgs e) 
    { 
     if (poundRadBtn.Checked) 
      if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
      { 
       Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
      } 
     else if (usdolRadBtn.Checked) 
      if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
      { 
       Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
      } 
     else if (ozdolRadBtn.Checked) 
      if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
      { 
       Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
      } 
     else if (ozdolRadBtn.Checked) 
      if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
      { 
       Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
      } 
    } 
+0

Там, кажется, не будет ли разница между первым и другими. Вы отлаживались, чтобы убедиться, что другие линии «Response.Write» на самом деле попали? – johna

+0

Другие response.writes не попадают. Я тестировал, добавляя метки и пытаясь установить текст. Я просто не понимаю, код копируется и вставляется для каждого переключателя, поэтому, если вы работаете, почему бы им не все? – ACostea

+0

Если другие response.writes не пострадали, проблема должна быть с линиями 'if'. Проходили ли вы каждую строку во время отладки и проверяли значения во время отладки в ваших строках if? – johna

ответ

0

Компилятор будет читать ваши данные else, если вложенные. Это будет выглядеть так:

  if (poundRadBtn.Checked) 
       if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
       { 
        Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
       } 
       else if (usdolRadBtn.Checked) 
        if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
        { 
         Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
        } 
        else if (ozdolRadBtn.Checked) 
         if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
         { 
          Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
         } 
         else if (ozdolRadBtn.Checked) 
          if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
          { 
           Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
          } 

Вот почему, если первый, если не удастся, другой, если заявления пойманы.

Переписывая его с пустым другим заявлением является одним из способов исправить это:

   if (poundRadBtn.Checked) 
       if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || 
        cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || 
        billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || 
        billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
       { 
        Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
       } 
       else 
       { } 
      else if (usdolRadBtn.Checked) 
        if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
        { 
         Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
        } 
       else { } 
      else if (ozdolRadBtn.Checked) 
       if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || 
        cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || 
        billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || 
        billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
       { 
        Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
       } 
       else 
       { } 
      else if (ozdolRadBtn.Checked) 
       if (cardList.Text == "" || cardNameBox.Text == "" || cardBox1.Text == "" || cardBox2.Text == "" || 
        cardBox3.Text == "" || cardBox4.Text == "" || expMonList.Text == "" || expYrList.Text == "" || 
        billNameBox.Text == "" || billAdd1Box.Text == "" || billAdd2Box.Text == "" || 
        billCtyBox.Text == "" || billPostBox.Text == "" || billCntryBox.Text == "") 
       { 
        Response.Write("<script>alert('Please ensure all fields have an entry');</script>"); 
       } 
       else 
       { } 
      } 

 Смежные вопросы

  • Нет связанных вопросов^_^