정보를 입력하지 않으면, 존재하지 않는 것에 따라 일련의 오류 메시지가 나타나는 양식을 만들려고합니다. 불행하게도, 나는 메시지를 담고있는 변수 Msg이 작동하지 않는 문제에 직면 해있다. (나는 생각한다.) 오류는 표시하지만 단락 형식이 아니라 목록에 표시됩니다.양식상의 다양한 오류 메시지에 추가하기
모든 오류를 줄 바꿈이 포함 된 메시지로 컴파일하는 방법은 무엇입니까?
"\ n"및 "\ r \ n"을 사용하지 않으려 고 시도했습니다.
는 내가 지금 가지고있는 것은 이것이다 :
Msg = Msg + "Text goes here for error messages...";
코드 :
private void btnSubmit_Click(object sender, EventArgs e)
{
//DECLARATIONS
int count = 0;
string Msg = "";
Boolean validatedState = true;
Boolean validateEntry = false;
DateTime endDate = new DateTime(2016, 03, 01);
DateTime startDate = new DateTime(2016, 03, 01);
//BEGIN SERIES OF IF/ELSE FOR CONFIRMING ENTRIES
if (Request["txtFirstName"].ToString().Trim() == "")
{
//displays yellow bg for missing input
txtFirstName.BackColor = System.Drawing.Color.Yellow;
Msg = Msg + "Please Enter a First Name" + "\r\n";
}//endif
else
{
txtFirstName.BackColor = System.Drawing.Color.White;
count += 1;
}//end else
if (Request["txtLastName"].ToString().Trim() == "")
{
//displays yellow bg for missing input
txtLastName.BackColor = System.Drawing.Color.Yellow;
Msg = Msg + "Please Enter a Last Name";
}//endif
else
{
txtFirstName.BackColor = System.Drawing.Color.White;
count += 1;
}//end else
if (Request["txtPayRate"].ToString().Trim() == "")
{
//displays yellow bg for missing input
txtPayRate.BackColor = System.Drawing.Color.Yellow;
Msg = Msg + "Please Enter a Pay Rate";
}//endif
else
{
txtFirstName.BackColor = System.Drawing.Color.White;
count += 1;
}//end else
if (Request["txtStartDate"].ToString().Trim() == "")
{
//displays yellow bg for missing input
txtStartDate.BackColor = System.Drawing.Color.Yellow;
validateEntry = false;
Msg = Msg + "Please Enter a Start Date";
}//endif
else
{
startDate = DateTime.Parse(Request["txtStartDate"]);
validateEntry = true;
}//end else
if (Request["txtEndDate"].ToString().Trim() == "")
{
//displays yellow bg for missing input
txtEndDate.BackColor = System.Drawing.Color.Yellow;
validateEntry = false;
Msg = Msg + "Please Enter an End Date";
}//endif
else
{
endDate = DateTime.Parse(Request["txtEndDate"]);
validateEntry = true;
}//end else
//END SERIES OF IF/ELSE FOR CONFIRMING ENTRIES
//START IF VALIDATE ENTRY
if (validateEntry == true)
{
if (DateTime.Compare(startDate, endDate) >= 0)
{
txtStartDate.BackColor = System.Drawing.Color.Yellow;
txtEndDate.BackColor = System.Drawing.Color.Yellow;
Msg = Msg + "The end date must be a later date than the start date.";
//The Msg text will be displayed in lblError.Text after all the error messages are concatenated
validatedState = false;
//Boolean value - test each textbox to see if the data entered is valid, if not set validState=false.
//If after testing each validation rule, the validatedState value is true, then submit to frmPersonnelVerified.aspx, if not, then display error message
Response.Write("<span style= 'BackColor:red'>Msg/<span>");
}
else //goes to this is dates are correct
{
validatedState = true;
count += 2;
txtStartDate.BackColor = System.Drawing.Color.White;
txtEndDate.BackColor = System.Drawing.Color.White;
}
}
//END IF VALIDATE ENTRY
//CONFIRMS ALL ARE CORRECT
if (count == 5 && validatedState == true)
{
Session["txtFirstName"] = txtFirstName.Text;
Session["txtLastName"] = txtLastName.Text;
Session["txtPayRate"] = txtPayRate.Text;
Session["txtStartDate"] = txtStartDate.Text;
Session["txtEndDate"] = txtEndDate.Text;
Response.Redirect("frmPersonnelVerified.aspx");
//sends to other page
}
else
{
Response.Write(Msg);
}
//ENDS CONFIRMATION OF CORRECT DATA
}//end Function: private void BtnSubmit_click...
}[![Current Error Response][1]][1]
자신의 롤링을 사용하는 대신 ASP.NET 유효성 검사 컨트롤을 사용하는 것이 좋습니다. https://msdn.microsoft.com/en-us/library/debza5t0.aspx –
안녕하세요, WebForms를 사용하고있는 것 같아요. 유효성 검사 컨트롤을 사용하는 것이 좋습니다. 유효성 검사 요약에 자동으로 경고 메시지가 표시됩니다. 필요한 것. 다음을 확인하십시오. https://msdn.microsoft.com/en-us/library/7kh55542(v=vs.71).aspx – JCM
이 방법을 계속 사용하려면 [Environment.NewLine] (https :// \ n \ r \ n '\ r \ n'대신에 /msdn.microsoft.com/en-us/library/system.environment.newline(v=vs.110).aspx) –