Comments on: Using Panel.DefaultButton property with LinkButton control in ASP.NET https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/ In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming. Tue, 08 Sep 2015 00:01:45 +0000 hourly 1 https://wordpress.org/?v=6.7.1 By: Joe https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-243773 Wed, 08 Oct 2008 02:57:47 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-243773 I have a question: I try to find out the value of the disabled property of linkbutton in javascript. It’s not a problem in IE but it’s undefined in Firefox. My problem is that although the link is disabled clicking it triggers onClientClick event which shows a message. I want to check if the link is disabled before showing the message however the disabled property is undefined in FireFox. Thank you in a advance for your help.

]]>
By: Jake H https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-237977 Thu, 11 Sep 2008 16:17:18 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-237977 The simplest, cross-browser approach I’ve seen is at this guy’s site:

http://weblogs.asp.net/jeff/archive/2005/07/26/420618.aspx

Just one line and you’re all set…
MyPasswordTextBox.Attributes.Add(“onKeyPress”, “javascript:if (event.keyCode == 13) __doPostBack(‘” + MySubmitButton.UniqueID + “‘,”)”)

]]>
By: Marlon Bohol https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-232193 Thu, 21 Aug 2008 02:32:17 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-232193 This is what i did in ASP.NET code behind and it works pretty well in both IE and FF:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        JavaScriptLoad()

    Private Sub JavaScriptLoad()

        Dim addClickFunctionScript As StringBuilder = New StringBuilder()

        addClickFunctionScript.Append("  function addClickFunction(id) {{ ")
        addClickFunctionScript.Append(" var b = document.getElementById(id); ")
        addClickFunctionScript.Append(" if (b && typeof(b.click) == 'undefined') b.click = function() {{ ")
        addClickFunctionScript.Append(" var result = true; if (b.onclick) result = b.onclick(); ")
        addClickFunctionScript.Append(" if (typeof(result) == 'undefined' || result) {{ eval(b.getAttribute('href')); }} ")
        addClickFunctionScript.Append(" }}}}; ")

        Dim addClickScript As String = "addClickFunction('{0}');"
        Dim ClickScript As String = String.Format(addClickScript, lnkLogin.ClientID)

        Page.ClientScript.RegisterStartupScript(Me.GetType(), "addClickFunctionScript", addClickFunctionScript.ToString(), True)
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "click_" + lnkLogin.ClientID, ClickScript, True)

    End Sub

corresponding .aspx file

1
2
3
4
<asp:Panel runat="server" DefaultButton="lbHello">
    First name: <asp:TextBox runat="server" ID="txtFirstName" />
    <asc:LinkButton ID="lbHello" runat="server" Text="Click me"  />
</asp:Panel>
]]>
By: Fernando Paiva https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-232134 Wed, 20 Aug 2008 22:42:57 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-232134 Based on Dave’s solution (post #7).

1
2
3
4
5
6
7
<asp:Panel ID="pnNewstatus" runat="server" DefaultButton="btnHiddenSubmit">
New Status:
<asp:TextBox ID="txbNewStatus" runat="server"/>
<asp:LinkButton ID="lnkBtnNewStatusCancel" runat="server" Text="Cancel" />
<asp:LinkButton ID="lnkBtnNewStatusSubmit" runat="server" Text="Submit" />
<asp:Button ID="btnHiddenSubmit" runat="server" />
</asp:Panel>

and then, on the code behind:

1
2
3
4
5
6
7
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  btnHiddenSubmit.Attributes.Add("style", "display:none;")
End Sub

Protected Sub lnkBtnNewStatusSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnNewStatusSubmit.Click, btnHiddenSubmit.Click
'Do What you need to do for those clicks
End Sub
]]>
By: Jared Holgate https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-214432 Wed, 18 Jun 2008 08:14:59 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-214432 Mdespesse’s point in 17 makes this solution work perfectly in FF3. Thanks.

]]>
By: Dmytro Shteflyuk https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-213961 Mon, 16 Jun 2008 13:48:25 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-213961 Nice point, mdespesse! Thanks for sharing your experience.

]]>
By: mdespesse https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-213920 Mon, 16 Jun 2008 11:25:53 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-213920 After some research, it seems that DOM specs stand that href attribute should be an URI and that to get the exact content of href, one should use :

1
eval(b.getAttribute('href'))
]]>
By: mdespesse https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-213914 Mon, 16 Jun 2008 10:45:56 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-213914 It seems that firefox 3 automatically htmlencode hrefs. So our :

1
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOption[...]

becomes :

1
javascript:WebForm_DoPostBackWithOptions(new%20WebForm_PostBackOption[...]

which obviously doesn’t work as expected.
To have it work again, change the end of addClickFunctionScript to :

1
eval(unescape(b.href));
]]>
By: Simon https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-212433 Mon, 09 Jun 2008 09:42:07 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-212433 Hi,

I have implemented this fix and it seems to be ok in most cases. However, if I have a form with asp.net validators then it only works once. e.g. Enter an invalid entry, press enter and the correct button is clicked. However, press enter again, and the wrong one is clicked!

Anyone have any ideas? Thanks in advance.

Simon.

]]>
By: Ramana https://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/comment-page-1/#comment-206539 Thu, 22 May 2008 03:59:52 +0000 http://kpumuk.info/asp-net/using-panel-defaultbutton-property-with-linkbutton-control-in-asp-net/#comment-206539 Hi uttam,

i am implemented what you are given the code in my aspx page, but in FireFox again its not working, when i enter key in textbox the cursor goes to next button, could you please give me any idea.

Thanks
Ramana

]]>