开发者

Whats the difference if I set hidden field value through html anchor OR asp.net linkbutton?

开发者 https://www.devze.com 2023-02-04 13:27 出处:网络
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 t

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.Val开发者_StackOverflow中文版ue != "")
        {               
            GetLinkPage(Convert.ToInt32(hdnSelectedLink.Value));

        }

Whats the problem ,Please suggest?


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 you were right dude.I used this in my javascript-

document.forms["aspnetForm"].submit();

its working fine now.

0

精彩评论

暂无评论...
验证码 换一张
取 消