編集可能なフィールドといくつかの必須フィールドを含むページがあります。問題は、ボタンをクリックして編集可能なフィールドをアクティブにして変更を加えるたびに、またはそれらの変更を適用/キャンセルするときに、Javascript が再び起動し、必須フィールドにさらに別の「必須フィールド」インジケーターが追加されることです。インジケーターは最初のロード時にのみ追加され、インターフェイスでクリックされたボタンの影響を受けないようにしたい。どうすればこれを達成できますか? Javascriptの「if」ステートメントに適切な条件が必要なだけだと思いますが、それが何であるかはわかりません。私はそれを研究し、乾きました。
これが私のマークアップです。リージョン全体を安全に無視できますUpdatePanel
。知っておく必要がある唯一のことは、その中のボタンが原因で、クリックごとに Javascript が再実行されるということです。
ありがとう!;)
<asp:Content runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function contentPageLoad() {
// Add "Required Field" Indicators
if (/*NEED CONDITION*/) {
$("h4.required").append(" <span class=\"r\">*</span>");
}
}
</script>
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
<!-- This is an updatable textfield. -->
<!-- PROBLEM!: LinkButtons here cause the double firing of the javascript above. -->
<!-- Remember that "ChildrenAsTriggers" defaults to True for UpdatePanel. -->
<asp:UpdatePanel ID="RequestorNameUpdatePanel" runat="server">
<ContentTemplate>
<asp:MultiView ID="RequestorName_mv" runat="server" ActiveViewIndex="0">
<asp:View ID="RequestorNameNormalView" runat="server">
<div class="rightCol">
<asp:LinkButton ID="editRequestorName" runat="server" />
<h6 class="inlineH">Requestor's Name: <asp:Label ID="RequestorName_lbl" runat="server"></asp:Label></h6>
</div>
</asp:View>
<asp:View ID="RequestorNameEditView" runat="server">
<div class="rightCol">
<asp:LinkButton ID="updateRequestorName" runat="server" />
<asp:LinkButton ID="cancelRequestorName" runat="server" />
<h6 class="inlineH">Requestor's Name: </h6>
<asp:DropDownList ID="RequestorName_ddl" runat="server" ViewStateMode="Inherit" AutoPostBack="False" ></asp:DropDownList>
<asp:TextBox ID="RequestorName_cb" runat="server" EnableViewState="True" AutoPostBack="False"></asp:TextBox>
<button id="RequestorName_btn" type="button" class="toggle ui-button"></button>
</div>
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
<!-- "REQUIRED" indicator from javascript appended here -->
<h4 class="required">First Name</h4>
<asp:TextBox ID="tbFirstName" runat="server"></asp:TextBox>
</asp:Content>