rufassa
asked on
Onclick not firing
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.
What am I not doing?
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" />
If you wanna add it for client side use this
eg :
<script type="text/javascript">
function foo()
{
alert("Sample");
}
</script>
.
.
.
<body>
<form runat="server">
<asp:Button ID="Test" Text="Click Me" runat="server" />
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
Test.Attributes.Add("oncli ck", "javascript:return foo();");
}
things will be okay
eg :
<script type="text/javascript">
function foo()
{
alert("Sample");
}
</script>
.
.
.
<body>
<form runat="server">
<asp:Button ID="Test" Text="Click Me" runat="server" />
</form>
</body>
protected void Page_Load(object sender, EventArgs e)
{
Test.Attributes.Add("oncli
}
things will be okay
you wanna make the server call ??
ASKER
I want a normal postback, a server call
ASKER
The problem I am having is that it seems as if I am doing everything right yet not getting the desired results. I am currently doing exactly what is being said in this link.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I set the PostBackURL property as the last comment suggested and the button started to fire but I got the following error as it fired.
runtimeError.bmp
runtimeError.bmp
If you want a client side script, just add onclick="function_name()" in the object.