Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on pageload i set default button like
C#
this.Form.DefaultButton = ImageButton2.UniqueID;


due to this some number code script is not working in form

the code is
HTML
<script type="text/javascript">
                       
 function alpha(e) 
            { 
	    var k;
            document.all ? k = e.keyCode : k = e.which;
            return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k==32);
	    }
</script>


XML
<asp:TextBox ID="txtpartyhallname"  runat="server" Width="200px" CssClass="WaterMarkedTextBox" onkeypress="return alpha(event)" >


I have to allow text only in this textbox.


Any suggestions required
Posted
Updated 7-Dec-11 22:15pm
v3
Comments
[no name] 8-Dec-11 4:16am    
EDIT: added "pre" tags

Hi,

Remove your pageload code it is fine working.


remove this:
C#
this.Form.DefaultButton = ImageButton2.UniqueID;
 
Share this answer
 
Comments
swarup65 8-Dec-11 4:47am    
if i remove page load code how can i will set default button for the page.
Jitendra Parida - Jeetu 8-Dec-11 5:04am    
Why you want to set default button for the page.
What is the your requirement please write here.
swarup65 8-Dec-11 6:57am    
Hi jitendra,

Actually iam working with content page if i didn't set default button, when the user submitting form if simply he press the enterkey in keyboard it's firing masterpage control default button.
so how can i will set default button
swarup65 8-Dec-11 6:59am    
Hi sravan,

by default textbox have not a property of onKeypress but it will support.

How can i will add javascript function in codebehind could u say?
swarup65 8-Dec-11 7:55am    
Hi sravan,
i tried like this in pageload
txtpartyhallname.Attributes.Add("onKeypress", "javascript:alpha(this)");

but it's not working
Hi Swarup,

Some changes make your code, it is fine work.

XML
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">

 function alpha(e)
            {
        var k;
            document.all ? k = e.keyCode : k = e.which;
            return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k==32 || k==13);
        }
</script>
<asp:TextBox ID="txtpartyhallname"  runat="server" Width="200px" CssClass="WaterMarkedTextBox" onkeydown="return alpha(event)" ></asp:TextBox>
    <asp:ImageButton ID="ImageButton2" runat="server"
        onclick="ImageButton2_Click" />

</asp:Content>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900