ASP.NET 2.0: استدعاء دالة جافا سكريبت من عند_التغيير مع AutoPostBack = صحيح
-
10-07-2019 - |
سؤال
ولدي DDL ASP.NET يشبه هذا عند عرض المصدر:
<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" />
ويمكن لأي شخص أن يرى مشكلة في استخدام عند_التغيير وAutoPostBack = "الحقيقي" على DDL مثل هذا؟ أسأل لأن لدينا بعض المستخدمين الذين لDoCustomStuff () لا يبدو ليتم استدعاؤها بشكل صحيح، وأنا أتساءل عما إذا كان من الممكن لل__doPostBack () ليتم تنفيذها قبل DoCustomStuff () يكمل عمله.
المحلول
وحاول أن نعلق إشارة إعادة النشر يدويا من هذا القبيل:
Page.ClientScript.RegisterClientScriptBlock(
typeof(_Default),
"PageScripts",
string.Format("function DoCustomStuff() { /* Your Code Here */ {0} }", Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))
);
testControl.Attributes["onchange"] = "DoCustomStuff();";
وهذا يعطيك إشارة العميل إعادة النشر:
Page.ClientScript.GetPostBackEventReference(testControl, string.Empty))
لا تنتمي إلى StackOverflow