this is a post back problem (I don’t want to use the client side to solve this issue , there must be a way to prevent the postBack then using the client side ) , i have a button when clicked it calls a javascript function from the code behind , but before it does this it post back the page , Question is : how can i skip the post back step and jump to the javascript part ??
<script type="text/javascript">
function hello(name) {
alert("hello world from javascript " + name)
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
code Behind :
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim Myname As String = "myName"
Dim cstype As Type = Me.GetType()
Page.ClientScript.RegisterStartupScript(cstype, "MyKey", "hello('" & Myname & "');", True)
End Sub
Use a client side handler instead of a server side handler. Remove
Button1_Clickand add your js call as anOnClientClickattribute value.Or, don’t use a server control at all: