如果我通过 html 锚点或 asp.net 链接按钮设置隐藏字段值有什么区别?
问题是,我有一组单击链接,我将这些链接的 linkId 设置为隐藏字段。首先,我的链接是 asp:linkbutton 和 onClientClick 我正在设置隐藏字段值。当时我能够从后面的代码中获取隐藏字段值,但是当我将链接更改为 HTML 锚点和 onClick 时,我设置了隐藏字段值,我没有得到空白的隐藏字段
。当我调试 JavaScript 时,它完美地设置了隐藏字段值,但为什么我没有在代码后面得到它——我的代码-
<a href="./ContentPage.aspx" data-flexmenu='flexmenu1' onclick="javascript:setPageLinkId(1);">
<script type="text/javascript">
function setPageLinkId(lnkPageId) {
debugger;
alert(lnkPageId);
document.getElementById('<%=hdnSelectedLink.ClientID %>').value = lnkPageId.toString();
}
</script>
//code behind- here I get blank hidden field
if (hdnSelectedLink.Value != null && hdnSelectedLink.Value != "")
{
GetLinkPage(Convert.ToInt32(hdnSelectedLink.Value));
}
问题是什么,请提出建议?
The problem is, I have a set of links onclick of those links I am setting the linkId into a Hidden field. First my link were asp:linkbutton ans onClientClick I was setting the hiddenfield value.that time I was able to get the hidden field value from code behind but when I changed my links to HTML anchor and onClick I set the hidden field value , I am not getting hidden field with blank
. when I debug JavaScript it is perfectly setting the hidden field value but why I am not getting it in code behind---my code-
<a href="./ContentPage.aspx" data-flexmenu='flexmenu1' onclick="javascript:setPageLinkId(1);">
<script type="text/javascript">
function setPageLinkId(lnkPageId) {
debugger;
alert(lnkPageId);
document.getElementById('<%=hdnSelectedLink.ClientID %>').value = lnkPageId.toString();
}
</script>
//code behind- here I get blank hidden field
if (hdnSelectedLink.Value != null && hdnSelectedLink.Value != "")
{
GetLinkPage(Convert.ToInt32(hdnSelectedLink.Value));
}
Whats the problem ,Please suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的理论是,点击锚点不会导致页面回发。相反,会发出对“ContentPage.aspx”的 HTTP GET 请求,这意味着任何表单值都不会发布到服务器。
您需要使用一个导致页面回发的控件...例如您之前使用的 ASP:LinkButton。
My theory is that the click on the anchor doesn't cause a postback to the page. Rather a HTTP GET Request to "ContentPage.aspx" is issued, meaning that any form values are not posted to the server.
You need to use a control that causes a postback to the page...for example ASP:LinkButton as you had before.
@Ozzy,你是对的,伙计。我在我的 javascript 中使用了这个 -
它现在工作正常。
@Ozzy you were right dude.I used this in my javascript-
its working fine now.