简体   繁体   中英

ASP setting control value from Javascript

From a list of names i dynamically create anchor tags on an aspx form page. The result of each is as follows with different names/IDs/titles.

 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

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

btnUpdateSql is defined hidden

 <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. 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. How can I set the button text in the Java function? 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.

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.

The advanatage is LinkButton has CommandArgument and CommandName . All links can use same Common Event , and you can see which link trigger the event by looking at the CommandArgument .

If you do not plan to postback to server, you will need to redesign the application to use Ajax . It is out of the scope of original question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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