Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
ASP .Net Web Controls
client-side code
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="MikeS, post: 4306754"] I need some validation on client side before submitting which causes a post back. I think that OnClientClick is for hooking up a client side function to a button. Return false from that function to prevent the postback. Or use the validation controls including the CustomValidator. <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If IsPostBack Then Response.Write(TextBox1.Text) End If End Sub </script> <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]" > <head runat="server"> <title>Untitled Page</title> <script> function checkIt() { var tb = document.getElementById("TextBox1"); var lbl = document.getElementById("Label1"); if (tb.value == "") { lbl.innerHTML = "Please enter something"; return false; } return true; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button id="Button1" runat="server" Text="Button" OnClientClick="return checkIt()"></asp:Button> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </div> </form> </body> </html> Note that using document.getElementById on server side controls is not so good as ID's for server side controls can get decorated and then their real ID is in their ClientID. So in that case you want to generate the script block server side and register it. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
ASP .Net Web Controls
client-side code
Top