This is a migrated thread and some comments may be shown as answers.

DefaultButton and RadAjaxPanel

3 Answers 256 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Sameh
Top achievements
Rank 1
Sameh asked on 10 Jan 2009, 12:18 PM
Dear Sir,
i have a problem with setting the DefaultButton,
I have a master page inside it i have an internal page, all the internal page is inside a RadAjaxPanel
when i am triyng to set the DefaultButton in code like this (Me.Form.DefaultButton=Button1.UniqueID) i got no result (the default button is not changed),

Please tell me how to set the DefaultButton.

Regards

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 12 Jan 2009, 01:29 PM
Hi Sameh,

Try using the FocusControl method of the RadAjaxPanel for your purpose:

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">  
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
</telerik:RadAjaxPanel> 
protected void Page_Load(object sender, EventArgs e)  
{  
   
    RadAjaxPanel1.FocusControl(TextBox1);  

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sameh
Top achievements
Rank 1
answered on 12 Jan 2009, 03:13 PM

Thank you Lana,

I am using this method to focus control (like Textbox), but i want a way to set the default button (to be clicked when pressing enter).

here is my scenario:

 

I have login form of two text boxes one is txtUser_Name and the other is txtPassword and btnLogin (button)

on the event of Page_Load I am using this line to set focus of the txtUser_Name:

RadAjaxPanel1.FocusControl(txtUser_Name);  

but I want another line to set the default button of the form to btnLogin, so the user can enter his user name and password and press enter (without clicking on the button with the mouse).

thank you

0
Iana Tsolova
Telerik team
answered on 13 Jan 2009, 08:09 AM
Hi Sameh,

In this case I suggest that you handle the body onkeypress client event and handle the [Enter] click there. For example as below:

<head runat="server">  
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
    <script type="text/javascript">  
    function keyDown(e)  
    {  
        if(e.keyCode == 13)  
        {  
            if(e.target)  
                $get("<%= Button1.ClientID %>").onclick();  
            if(e.srcElement)  
                $get("<%= Button1.ClientID %>").click();  
        }  
    }  
    </script> 
    </telerik:RadCodeBlock> 
</head> 
<body onkeydown="keyDown(event)">  
    <form id="form1" runat="server">  
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">  
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
                <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 
            </telerik:RadAjaxPanel> 
        </div> 
    </form> 
</body> 

I hope this helps.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Sameh
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Sameh
Top achievements
Rank 1
Share this question
or