2009-03-11 14 views
0

Ben kaynak görüntülediğinizde şöyle bir ASP.NET DDL vardır:ASP.NET 2.0: AutoPostBack ile onChange gelen bir javascript işlevinin çağrılması = true

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

Bu .cs sayfasında şöyle :

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

kimse böyle bir DDL üzerinde Onchange ve AutoPostBack = "true" kullanarak bir sorunu görebilir mi? DoCustomStuff() 'ın doğru çağrıldığını görmediği bazı kullanıcılar var diye soruyorum ve DoCustomStuff()' ın işini tamamlamadan önce __doPostBack() 'ın uygulanmasının mümkün olup olmayacağını merak ediyorum.

cevap

0

deneyin böyle elle işlem bildirim referansı eklemek:

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

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

bu size geri gönderme istemci tarafı referansını verir:

Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))