abonjour
asked on
I can't focus a textbox control neither submit with enter key within content pages in Asp.net 2.0
I've a master page - content page web site and my problem is that I can't focus a control within the content pages in asp.net 2.0
Same thing happend when I want to enable the enter key to submit information in a content page.
I don't have the atribute in the content page to asign the default button.
How can I focus a control within a content page?
How can I submit a content page with the enter key?
Same thing happend when I want to enable the enter key to submit information in a content page.
I don't have the atribute in the content page to asign the default button.
How can I focus a control within a content page?
How can I submit a content page with the enter key?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I understood your problem and suggest you to use SetFocus() method instead of using javascript. In this case you don't have to manually coding javascript and place it somethere in content page. It's a best way to set focus on control. You can use SetFocus method on codebehind of content page or on content aspx and focus would be set on control inside a content page.
Second scenario can be changed using div tag placed inside content page.
To submit form after clicking "Enter" button you just need to correctly specify buttons names in javascript "OnKey" function. They names would like ctl00_ContentPlaceHolder1_ TextBox1, ctl00_ContentPlaceHolder1_ TextBox2 etc...
<asp:Content ID="Content1" ContentPlaceHolderID="Cont entPlaceHo lder1" Runat="Server">
<div onkeypress="OnKey();">
<asp:textbox id="x" runat="server"></asp:textb ox>
<asp:textbox id="y" runat="server"></asp:textb ox>
<asp:textbox id="z" runat="server"></asp:textb ox>
<asp:button id="a" text="a" runat="server"></asp:butto n>
<asp:button id="b" text="b" runat="server"></asp:butto n>
<asp:button id="c" text="c" runat="server"></asp:butto n>
<asp:button id="d" text="d" runat="server"></asp:butto n>
<script language = "javascript">
function OnKey()
{
if (eval(window.event.keyCode ) == 13)
{
document.all['c'].focus();
............
............
document.forms(0).submit() ;
}
}
</script>
</div>
</asp:Content>
Second scenario can be changed using div tag placed inside content page.
To submit form after clicking "Enter" button you just need to correctly specify buttons names in javascript "OnKey" function. They names would like ctl00_ContentPlaceHolder1_
<asp:Content ID="Content1" ContentPlaceHolderID="Cont
<div onkeypress="OnKey();">
<asp:textbox id="x" runat="server"></asp:textb
<asp:textbox id="y" runat="server"></asp:textb
<asp:textbox id="z" runat="server"></asp:textb
<asp:button id="a" text="a" runat="server"></asp:butto
<asp:button id="b" text="b" runat="server"></asp:butto
<asp:button id="c" text="c" runat="server"></asp:butto
<asp:button id="d" text="d" runat="server"></asp:butto
<script language = "javascript">
function OnKey()
{
if (eval(window.event.keyCode
{
document.all['c'].focus();
............
............
document.forms(0).submit()
}
}
</script>
</div>
</asp:Content>
ASKER
I think I have to acces the form of the masterpage but I don't know how.
This is the code in the content page and I want to set focus in this textbox.
<asp:content id="Content2" contentplaceholderid="Page
<asp:TextBox ID="txtCosto" runat="server" ></asp:TextBox>
</asp:content>