Onclick not firing

2019-03-06 18:09发布

I have a set of buttons on my master page (I have attached the code below) but no onclick event is being raised. I pulled the final page source and no onclick event was present. As you can see I tried a few different approaches to solve the problem. I am looking for a normal postback to the server but I am getting nothing when I click any of these buttons.

What am I not doing?

--Master

<asp:Button ID="btnSubmit" CssClass="btn" runat="server" OnClick ="Button_Click" />
<asp:Button ID="btnSave" CssClass="btn" CommandArgument="1" CommandName="ButtonPress" runat="server" OnClick="Button_Click" />
<asp:Button ID="btnClear" CssClass="btn" CommandArgument="8" CommandName="ButtonPress" runat="server" OnCommand="Button_Command" />
<asp:Button ID="btnCancel" CssClass="btn" CommandArgument="4" CommandName="ButtonPress" runat="server" OnCommand="Button_Command" />

--Master Code Behind

Protected Sub Button_Command(ByVal sender As Object, ByVal e As CommandEventArgs) Handles btnCancel.Command, btnClear.Command
    Session("ButtonClicked") = e.CommandArgument
End Sub

Protected Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click, btnSubmit.Click
    Session("ButtonClicked") = CType(sender, Button).CommandArgument
End Sub 

--Page Source

<input type="submit" name="ctl00$btnSubmit" value="Submit" id="ctl00_btnSubmit" class="btn" />
<input type="submit" name="ctl00$btnSave" value="Save" id="ctl00_btnSave" class="btn" /> 
<input type="submit" name="ctl00$btnClear" value="Clear" id="ctl00_btnClear" class="btn" />
<input type="submit" name="ctl00$btnCancel" value="Cancel" id="ctl00_btnCancel" class="btn" />

1条回答
叼着烟拽天下
2楼-- · 2019-03-06 18:30

I found the issue. Here was the problem. On the master Page I had to change this:

< script language="javascript" src="scriptLibrary.js" type="text/javascript"/>

To this:

< script language="javascript" src="scriptLibrary.js" type="text/javascript">< /script>

And after that it performed a normal postback without errors.

查看更多
登录 后发表回答