Click here to Skip to main content
15,910,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
Can anyone tell me, how I can get the value of hidden field using javascript.

Here is aspx code

<asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" CssClass="delbutton" CommandArgument='<%#Eval("noticeid") %>'>Delete
<asp:HiddenField ID="hfID" Value='<%#Eval("noticeid") %>' runat="server" />


Here what I'm trying, I'm binding value to hidden field. Using this value I'm going to delete record using Json.

I tried following JavaScript

function funDelete() {
            alert("Start");
            if (confirm("Do you want to delete this record?")) {
                alert("Step 1");
                try {
                    $(document).ready(function() {
                        $('#lnkDelete').click(function() {
                            alert("Ready");
                        });
                        
                    });
                    //GET ID OF RECORD TO BE DELETED
                    var id = document.getElementById('<% =hfID.ClientID %>').value;
                    //$('#hfID').val();
                    
                    alert("ID:" + id);
                    $.ajax({
                        type: "POST",
                        url: "QCNotice.aspx/deleteComment",
                        data: "{'args':'" + id + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function() {
                            alert("IN");
                            row.css("background-color", "Red");
                            row.fadeOut(500, function() {
                                row.remove();
                            });
                        },
                        error: function(event, request, settings) {
                            alert("Ajax Error");
                        }
                    });
                }
                catch (e) {
                    alert("Error:" + e.message);
                }
            }
            return false;
        }


It gives error saying: Overload resolution failed because no accessible 'Write' can be called with these arguments

Any idea, where I'm going wrong??

Thanks in advance
Posted
Updated 7-Jul-11 2:42am
v3

yer put there = sign.

<pre>var id = document.getElementById('<%=hfID.ClientID %>').value;</pre>
 
Share this answer
 
Comments
dhage.prashant01 7-Jul-11 8:28am    
It gives error:
Overload resolution failed because no accessible 'Write' can be called with these arguments

Any idea?
ParthaDinda 7-Jul-11 8:42am    
I think your code is in grid view or repter?
So it can't find hidden feild value.
Try to add onclientclick event in row_created/item-created event and add your javascript function from there you can pass your require value.
dhage.prashant01 7-Jul-11 8:47am    
In RowDataBound I'm trying
lnkDelete.Attributes.Add("onclick", "return funDelete();")

I think, i have to pass command-argument in funDelete()
Right?
ParthaDinda 7-Jul-11 8:51am    
yes send your value as parameter and and do your work.
dhage.prashant01 7-Jul-11 8:55am    
I tried:
lnkDelete.Attributes.Add("onclick", "return funDelete(" + intID + ");")

It gives error:
Conversion from string "return funDelete(" to type 'Double' is not valid.

how can we pass parameter?
You have to add = before hfID.ClientID in Javascript.
var id = document.getElementById("<% =hfID.ClientID %>").value;
 
Share this answer
 
v2
Comments
dhage.prashant01 7-Jul-11 8:26am    
It gives me error:
Overload resolution failed because no accessible 'Write' can be called with these arguments.

Any idea, what does it mean?
Toniyo Jackson 7-Jul-11 8:32am    
I think this error not related to this javascript. Update the question by posting the code.
dhage.prashant01 7-Jul-11 8:35am    
Yes now I have put my JS code.
var id=$get('<%= hdnOrgid.ClientID %>').value
 
Share this answer
 
Comments
VICK 5-Dec-13 7:00am    
does it make sense to reply against the already SOLVED question which is two years old as well.. ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900