开发者

default LinkButton on enter in a Master Page

开发者 https://www.devze.com 2023-01-29 08:53 出处:网络
I looked through and through a开发者_如何学编程nd found no clean solution for this. A colleague of mine did find a pretty dirty solution but I don\'t see why the solutions in the links reference below

I looked through and through a开发者_如何学编程nd found no clean solution for this. A colleague of mine did find a pretty dirty solution but I don't see why the solutions in the links reference below does not work when I place it in a master page. I have a master page that basically has a textbox and a linkbutton, when I hit the enter key, the default button for the child page gets called instead.

  1. http://weblogs.asp.net/jeff/archive/2005/07/26/420618.aspx
  2. set linkbutton as default button for asp:panel in asp.net (Ahmad's Solution)

any insight on this please? thanks :)

I will post the dirty solution when I get to work tomorrow.

EDIT: here's the dirty (i think) solution:

string id = ctlToClick.UniqueID;
string someJavascript = //see below
EmailTextBox.Attributes.Add("OnKeyPress", someJavascript);

The javascript (placed it here so StackOverflow can format it better):

javascript:if (window.event){
    if(parseInt(window.event.keyCode) == 13){
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('" + id + "', '', true, 'Login', '', false, true));
    return false;
    }
}

Is this really the only solution for this?


Did you try setting the defaultButton property?

<form id="Form1"
        defaultbutton="lnkNextPage" 
        runat="server">

Where lnkNextPage is the LinkButton control's id.


I think you need a simple javascript to control your tab/enter keys. I have run into this before an there was no way to make the default button solution work.

The idea is simple - check each key that is entered while in the text box. If the key presed is enter or tab, find the button either by jquery or document.GetElementById('id') and invoke the click event on the button.

the form's default button doesn't work in asp.net since a): there is only 1 form, and b): for different text boxes you want to be able to control which button is actually clicked (on tab/enter).

A simple javascript file solves this.

<bleepzter/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号