문제

소스를 볼 때 다음과 같이 보이는 ASP.NET DDL이 있습니다.

<select name="testControl" onchange="DoCustomStuff();setTimeout('__doPostBack(\'testControl\',\'\')', 0)" id="testControl">

.CS 페이지에서 이렇게 보입니다.

<asp:DropDownList ID="testControl" runat="server" onchange="DoCustomStuff()" OnSelectedIndexChanged="testControl_Changed" AutoPostBack="true" />

누구든지 다음과 같은 DDL에서 OnChange 및 AutoPostback = "True"를 사용하는 데 문제가 있습니까? DocustomStuff ()가 올바르게 호출되지 않는 사용자가 있기 때문에 묻습니다. DocustomStuff ()가 작업을 완료하기 전에 __dopostback ()를 실행할 수 있는지 궁금합니다.

도움이 되었습니까?

해결책

다음과 같은 수동으로 Postback 참조를 첨부하십시오.

Page.ClientScript.RegisterClientScriptBlock(
  typeof(_Default), 
  "PageScripts", 
  string.Format("function DoCustomStuff() { /* Your Code Here */ {0} }", Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))
);

testControl.Attributes["onchange"] =  "DoCustomStuff();";

이것은 Postback Client Side Reference를 제공합니다.

Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top