0

I've got two questions - first of all, why does .net render a javascript onclick event for asp buttons when there's a custom validator on the same page, and secondly, how can I get rid of the javascript?

It works fine when javascript is turned off, so I don't know what the point of it is. Here's a mini example:

<form id="form1" runat="server">

    <asp:Button ID="Button1" OnClick="Button1_Click" Text="test" runat="server" />

    <asp:CustomValidator ID="CustomValidator1" runat="server" 
        OnServerValidate="Stuff_Validate" EnableClientScript="false">
    </asp:CustomValidator>

</form>

This will generate the following html for the button:

<input type="submit" name="Button1" value="test" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button1" />

Without the custom validator, it's:

<input type="submit" name="Button1" value="test" id="Button1" />

Any ideas?

Thanks,

Annelie

4

2 に答える 2

0

カスタム検証はjavascriptを介して行われるため、javascriptが追加されます。それはそこにあることを意味します。検証はどのように行われると思いますか?javascriptを削除した場合、検証は機能しません。

于 2011-02-02T10:07:07.683 に答える
0

何を見ると、そのSystem.Web.UI.WebControls.Button理由がわかります。

GetPostBackOptions()、(現在の検証グループ内の)ページにバリデーターがある場合、ポストバック用のスクリプトが生成されます。

次に、でAddAttributesToRender()、スクリプトが存在する場合、それらはonclickイベントでレンダリングされます。

これを回避する必要がある場合は、カスタムボタンを作成する必要があります

于 2011-02-02T10:19:19.297 に答える