使用javascript更改asp:button中的文本 [英] changing text in asp:button using javascript

查看:72
本文介绍了使用javascript更改asp:button中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在asp:button中使用javascript更改值,以在单击它时捕获后面代码的值,默认值为Text ="show"

当我使用javascript"left:......."
时,我看到页面上的更改 但是当我用字符串a = button.text捕获代码后面的按钮时,我得到的是默认值"show",而不是网页上按钮上显示的值.

这是用于更改按钮上文本的javascript代码

Hello, I would like to change the value using javascript in a asp:button to catch the value on the code behind when i click on it, the default value Text="show"

i see the change on the page when i use the javascript "left: ......."
but when i catch the button in code behind with string a = button.text i get the default value "show" and not the value shown on the button on the webpage.

this is the javascript code that changes the text on the button

document.getElementById("hidden1").text = ("Left: " + $(this).parent().dialog(''widget'').position().left + " Top: " + $(this).parent().dialog(''widget'').position().top);

// click the button
document.getElementById("hidden1").click();



我也不想在单击按钮时重新加载页面,我只想从后面的代码中捕获按钮中的值,ajax可以解决这个问题吗?

谁能帮忙,谢谢



Also i don''t want to reload the page when the button i clicked, i only want to catch the value in the button from code behind, can ajax solve this?

Can anyone help, Thanks

推荐答案

(this).parent().dialog("widget").position().left +"Top:" +
(this).parent().dialog(''widget'').position().left + " Top: " +


(this).parent().dialog(``widget'').position().top); //点击按钮 document.getElementById("hidden1").click();
(this).parent().dialog(''widget'').position().top); // click the button document.getElementById("hidden1").click();



我也不想在单击按钮时重新加载页面,我只想从后面的代码中捕获按钮中的值,ajax可以解决这个问题吗?

任何人都可以帮忙,谢谢



Also i don''t want to reload the page when the button i clicked, i only want to catch the value in the button from code behind, can ajax solve this?

Can anyone help, Thanks


无法在您使用javascript对其进行了更改的代码中获取Text值.有关详细原因,请访问以下链接

http://msdn.microsoft.com/en-us/library/system. web.ui.ipostbackdatahandler.aspx [ ^ ]

由于默认按钮服务器控件未实现IpostbackDataHandler,因此您将无法从服务器端代码获取Text数据.因此,对于另一种方法,请尝试使用HiddenField并在更新buton控件的文本值时更新值,并在服务器端获取该值.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.aspx [ ^ ]
Its not possible to get the Text value in code behind which you have changed by using javascript. For a detailed reason visit the following link

http://msdn.microsoft.com/en-us/library/system.web.ui.ipostbackdatahandler.aspx[^]

as the default button Server control dowsn''t implement IpostbackDataHandler you will not be able to get the Text data from server side code. So for an alternative approach try to use the HiddenField and update the value when you are updating the text value of the buton control and get the value at the server side.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.aspx[^]


这篇关于使用javascript更改asp:button中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆