c# 서버측 버튼을 클릭하여 confirm 기능 구현
6091 단어 confirm
일반 서버 button 컨트롤:
<asp:Button ID="Button1" runat="server" OnClientClick="if(!confirm('Submit form?')){return false;}" OnClick="Button1_Click" Text="Button" />
심볼에 OnClientClick 이벤트를 등록하면 Submit 전에 사용자에게 확인하고 확인한 후에submit을 하고 그렇지 않으면 submit을 하지 않습니다.
GridView의 command 버튼:
protected void gvProject_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
string[] parameters = e.CommandArgument.ToString().Split('|');
int rowIndex = Convert.ToInt32(parameters[0]);
bool confirmResult = false;// , false
if (parameters.Length == 2)
{
bool.TryParse(parameters[1], out confirmResult);
}
if (!confirmResult)//
{
//
string commandArgument = e.CommandArgument.ToString() + "|true";
string commandProjectName = this.gvProject.Rows[rowIndex].Cells[0].Text;
string scriptString = @"
<script>
if(window.confirm(' {" + commandProjectName + @"} ?'))
{
__doPostBack('gvProject','$" + commandArgument + @"')
}
</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "billConfirmAlert", scriptString);
}
else//
{
// DataKeys projectID
int projectID = Convert.ToInt32(this.gvProject.DataKeys[rowIndex].Values["ProjectID"]);
projectController.ActivateProject(projectID, "");
//
ShowNotActivatedProject();
}
}
catch (Exception ex)
{
this.lblResult.Text = string.Format(" :{0}", ex.Message);
}
}
주석이 상세하니 여러분 직접 보세요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript confirm 다양한 사용 방법 분석메시지 매개 변수에 포함된 정보를 먼저 표시하고 선택할 수 있는 두 개의 대답 "ok"와 "cancel"을 제공한 다음 사용자가 그 중 하나를 선택할 때까지 기다립니다.사용자가 "ok"를 선택하면true로 돌아갑니다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.