JavaScript 코드를 프로그램에 추가하면 버튼 OnClick 이벤트가 실행되지 않고 왜 이런 현상이 발생합니까? 진행 막대의 C# 코드를 전달하고 클릭하면 진행률 막대가로드됩니다. 버튼 클릭 이벤트가 발생하지 않는 이유를 알고 싶습니다.click 이벤트가 발생하지 않습니다.
HTML과 자바 스크립트 코드 : ProgressBar의를 들어
<asp:Button ID="Confirm_btn" CssClass="confirmBtn" runat="server" Text="Generate Presentation" UseSubmitBehavior="true"
ClientIDMode="Static" OnClick = "Confirm_Click" />
</td></tr>
<tr><td colspan="2" align="center">
<div id="progressbar" style="width:500px"></div>
</td></tr>
</table>
</div>
<asp:Label ID="error" runat="server" ClientIDMode="Static"
EnableViewState="False" Font-Names="Arial"></asp:Label>
</center>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
<script type="text/javascript">
$.updateProgressbar = function() {
//Calling PageMethod for current progress
PageMethods.OperationProgress(function (result) {
//Updating progress
$("#progressbar").progressbar('value', result.progress)
//If operation is complete
if (result.progress == 100) {
//Enable button
$("#Confirm_btn").attr('disabled', '');
}
//If not
else {
//Reset timer
setTimeout($.updateProgressbar, 500);
}
});
};
$(document).ready(function() {
//Progressbar initialization
$("#progressbar").progressbar({ value: 0 });
//Button click event
$("#Confirm_btn").click(function (e) {
e.preventDefault();
//Disabling button
$("#Confirm_btn").attr('disabled', 'disabled');
//Making sure that progress indicate 0
$("#progressbar").progressbar('value', 0);
//Call PageMethod which triggers long running operation
PageMethods.Operation(function (result) {
if (result) {
//Updating progress
$("#progressbar").progressbar('value', result.progress)
//Setting the timer
setTimeout($.updateProgressbar, 500);
}
});
});
});
</script>
</asp:Content>
C# 코드 :
/// <summary>
/// PageMethod for triggering long running operation
/// </summary>
/// <returns></returns>
[System.Web.Services.WebMethod(EnableSession = true)]
public static object Operation()
{
HttpSessionState session = HttpContext.Current.Session;
//Separate thread for long running operation
ThreadPool.QueueUserWorkItem(delegate
{
int operationProgress;
for (operationProgress = 0; operationProgress <= 100; operationProgress = operationProgress + 2)
{
session["OPERATION_PROGRESS"] = operationProgress;
Thread.Sleep(1000);
}
});
return new { progress = 0 };
}
/// <summary>
/// PageMethod for reporting progress
/// </summary>
/// <returns></returns>
[System.Web.Services.WebMethod(EnableSession = true)]
public static object OperationProgress()
{
int operationProgress = 0;
if (HttpContext.Current.Session["OPERATION_PROGRESS"] != null)
operationProgress = (int)HttpContext.Current.Session["OPERATION_PROGRESS"];
return new { progress = operationProgress };
}
}
C# 코드 버튼을 클릭 이벤트에 대한 :
protected void Confirm_Click(object sender, EventArgs e)
{
// my process run here
}
'OnClientClick = "시도해보기 firm_Click "' – HShbib
나는 OnClientClick ="Confirm_Click "을 시도했다. 이것은 jscpirt 코드를 실행하기 위해 예외를 던진다. C# 클래스에서 – user2082903
메서드는 OnClick이다 – user2082903