Asp:LinkBut​​ton href 值应用于表 onclick

发布于 2024-11-13 16:04:02 字数 1094 浏览 2 评论 0原文

我正在尝试在我们的 Web 应用程序中国际化按钮,到目前为止我已经能够使用精灵图像构建我们的按钮并应用相关的 css 类来构建按钮。

我将其布局为以下结构:

<table cellpadding="0" cellspacing="0" class="pwbtn" onmouseout="this.className='pwbtn';"
    onmouseover="this.className='pwbtnh';">
    <tr>
        <td class="a1">
        </td>
        <td class="a2" onclick="CallShowBlocker()">
            <asp:linkbutton id="ButtonNext" onclientclick="PreNavigationScript();" runat="server"
                cssclass="RemoveLinkStyle"></asp:linkbutton>
        </td>
        <td class="a3">
        </td>
        <td class="spacer">
        </td>
    </tr>
</table>

目前,按钮按预期显示,但用户必须准确单击按钮的文本才能触发其事件。

我想将 linkbutton 的 href 值应用到 onlcick 表中,这样当用户单击图像内的任意位置时,它将触发该事件。

另外,我的 href 值是通过 C# 中的事件处理程序构建的,并产生以下 href 值:

"javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ContWizard2$Wizard1$cFooter$ButtonNext', '', true, '', '', false, true));"

如果我在这里不够清楚或错过了您需要查看的代码的任何部分,请告诉我并谢谢提前。

I am attempting to internationalise buttons within our web application and so far i have been able to build our buttons up using a sprite image and applying the relevant css classes to build the button.

I have this laid out in the following structure:

<table cellpadding="0" cellspacing="0" class="pwbtn" onmouseout="this.className='pwbtn';"
    onmouseover="this.className='pwbtnh';">
    <tr>
        <td class="a1">
        </td>
        <td class="a2" onclick="CallShowBlocker()">
            <asp:linkbutton id="ButtonNext" onclientclick="PreNavigationScript();" runat="server"
                cssclass="RemoveLinkStyle"></asp:linkbutton>
        </td>
        <td class="a3">
        </td>
        <td class="spacer">
        </td>
    </tr>
</table>

At the moment the buttons are displayed as expected however the user has to click exactly on the text for the button to fire its event.

I want to apply the href value of the linkbutton to the tables onlcick so when the user clicks anywhere inside the image it will fire the event.

Also, my href value is built up via an event handler in C# and results in the following href value:

"javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ContWizard2$Wizard1$cFooter$ButtonNext', '', true, '', '', false, true));"

If I haven't been clear enough here or missed any parts of code you would need to see, please let me know and thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灼疼热情 2024-11-20 16:04:02

在我获得更多代表之前,我必须在这里回答您而不是发表评论。一个很好的建议是保留您的代码,但不要使用链接按钮(这可能会限制您必须点击的位置),您可以使用图像按钮并将 imageurl 属性分配给您的图片/图标。

由于两种类型的按钮之间的差异很小,因此您根本不必进行太多更改。

让我知道是否有帮助。

-JJ

Until I get more rep, I'll have to answer you here as opposed to a comment. A nice suggestion would be to maintain your code behind, but instead of using a linkbutton (which may cause limitations on where you must click), you could use a image button and assign the imageurl property to your picture/icon.

Since there is minimal difference between the two types of buttons, you shouldn't have to change much at all.

Let me know if that helps.

-JJ

此岸叶落 2024-11-20 16:04:02

万一有人发现这个并想知道如何解决它。

我删除了表格外部的 LinkBut​​ton。使用表 onclick 属性,我创建了一个新的 Javascript 函数,该函数传递 LinkBut​​ton clientID。

单击按钮时,ID 会传递给 Javascript 函数,然后我们触发 link.click() 来执行链接操作。见下文:

<asp:linkbutton id="LinkButton1" runat="server" causesvalidation="False" cssclass="RemoveLinkStyle"></asp:linkbutton>
<table cellpadding="0" cellspacing="0" class="pwbtn" onclick="CallShowBlocker(); ExecuteLink('<%=ButtonYes.ClientID %>');"
    onmouseout="this.className='pwbtn';" onmouseover="this.className='pwbtnh';">
    <tr id="trButtonYes" runat="server" visible="false">
        <td class="a1">
        </td>
        <td class="a2" onclick="CallShowBlocker()">
            <%= this.resourceManager.GetString("yes") %>
        </td>
        <td class="a3">
        </td>
        <td class="spacer">
        </td>
    </tr>
</table>

function ExecuteLink(linkID)
{ 
    var link = document.getElementById(linkID); 
    link.click();
}

In case anyone finds this and is wondering how to fix it.

I removed the LinkButton outside of the table. Using the tables onclick attribute, I created a new Javascript function which passed the LinkButton clientID.

When the button is clicked, the ID is passed to the Javascript function, and we fire link.click() to execute the links action. See below:

<asp:linkbutton id="LinkButton1" runat="server" causesvalidation="False" cssclass="RemoveLinkStyle"></asp:linkbutton>
<table cellpadding="0" cellspacing="0" class="pwbtn" onclick="CallShowBlocker(); ExecuteLink('<%=ButtonYes.ClientID %>');"
    onmouseout="this.className='pwbtn';" onmouseover="this.className='pwbtnh';">
    <tr id="trButtonYes" runat="server" visible="false">
        <td class="a1">
        </td>
        <td class="a2" onclick="CallShowBlocker()">
            <%= this.resourceManager.GetString("yes") %>
        </td>
        <td class="a3">
        </td>
        <td class="spacer">
        </td>
    </tr>
</table>

function ExecuteLink(linkID)
{ 
    var link = document.getElementById(linkID); 
    link.click();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文