简体   繁体   English

来自Java脚本的ASP设置控件值

[英]ASP setting control value from Javascript

From a list of names i dynamically create anchor tags on an aspx form page. 从名称列表中,我在aspx表单页面上动态创建锚标记。 The result of each is as follows with different names/IDs/titles. 每个结果如下,具有不同的名称/ ID /标题。

 From a list of names i dynamically create achor tags on an aspx form page. <a target= href="mailto:johnbrown@site.net" onclick="updateSql(document.getElementById('PersonJB'))" runat="server" id="PersonJB" title="JB">John Brown</a> 
Java function updateSql is Java函数updateSql是

  function update(passLink) { /* alert("this dialogue has been invoked through codebehind."); */ document.getElementById('<%= btnUpdateSql.ClientID%>').click(); } 

btnUpdateSql is defined hidden btnUpdateSql被定义为隐藏

 <asp:Button ID="btnUpdateSqlt" runat="server" Text="Button" CssClass="hidden"/> 

It all seems to work. 一切似乎都有效。 except I want the click event to be aware of the different link that was clicked. 除了我希望click事件了解点击的其他链接。 What I want to achieve: Update btnUpdateSql text with the ID or title of the passed link before called the click event in the javascript function. 我要实现的目标:在javascript函数中调用click事件之前,使用传递的链接的ID或标题更新btnUpdateSql文本。 How can I set the button text in the Java function? 如何在Java函数中设置按钮文本? Or how can i use another hidden field? 或者我如何使用另一个隐藏字段? The purpose being to update SQL table in the click event using the initials as a key. 目的是使用首字母作为键来更新click事件中的SQL表。

First of all, multiple links triggering a button click event under the hood is very fragile. 首先,在引擎盖下触发按钮单击事件的多个链接非常脆弱。

Why not use LinkButton since you are posting back to server anyway. 为什么不使用LinkBut​​ton,因为无论如何都要回发到服务器。

The advanatage is LinkButton has CommandArgument and CommandName . 优点是LinkBut​​ton具有CommandArgumentCommandName All links can use same Common Event , and you can see which link trigger the event by looking at the CommandArgument . 所有链接都可以使用相同的Common Event ,并且可以通过查看CommandArgument查看哪个链接触发了该事件。

If you do not plan to postback to server, you will need to redesign the application to use Ajax . 如果您不打算回发到服务器,则需要重新设计应用程序以使用Ajax It is out of the scope of original question. 这超出了原始问题的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM