Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
Its very High Priority task, please help.
Can any one help me on the following.
I have gridview on my page,and it contains Linkbutton.

On clicking of Linkbutton i am calling server side code from where i want to call Javascript Function.
To Javascript function i want to send three parameters,ID,Name and third parameter is Hiddnefield Control.

By writing below code i am able to pass only ID and Name but not able to pass Hidden Field Control.

If i am trying pass Hidden field as well then my javascript does not call.

Can any one please help me on this,Its on high Priority.

Below is code.

Need your precious help.
I have tried so many things but it was not up to the mark.

What I have tried:

ASP.NET
<asp:GridView ID="MyGrid" runat="server" AutoGenerateColumns="false" OnRowCommand="MyGrid_RowCommand">
        <columns>
            <asp:TemplateField HeaderText="Application ID">
                <itemtemplate>
                    <asp:Label ID="lblApplicationID" runat="server" Text='<%# Bind("application_id") %>'>
                    <asp:HiddenField ID="hdnApplicationID" runat="server" Value='<%# Bind("application_id") %>'>
                    
                
            
            <asp:TemplateField HeaderText="Application Type">
                <itemtemplate>
                    <asp:Label ID="lblApplicantType" runat="server" Text='<%# Bind("applicant_type") %>'>
                    <asp:HiddenField ID="hdnApplicantType" runat="server" Value='<%# Bind("applicant_type") %>'>
                    
                
            
            <asp:TemplateField HeaderText="Application Name">
                <itemtemplate>
                    <asp:Label ID="lblApplicatName" runat="server" Text='<%# Bind("applicant_name") %>'>
                    <asp:HiddenField ID="hdnApplicantName" runat="server" Value='<%# Bind("applicant_name") %>'>
                    
                
            
            <asp:TemplateField HeaderText="Document Type">
                <itemtemplate>
                    <asp:Label ID="lblDocumentType" runat="server" Text='<%# Bind("DOCUMENT_TYPE") %>'>
                    <asp:HiddenField ID="hdnDocumentType" runat="server" Value='<%# Bind("DOCUMENT_TYPE") %>'>
                    
                
            
            <asp:TemplateField HeaderText="Download">
                <itemtemplate>
                    <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" CommandName="DownloadAddressProof">
                    <asp:HiddenField ID="hdnDocument" runat="server" Value="C:\Users\Prasanna\Desktop\SALARY SLIP JAN\GS POINT\ABHILASHA SALARY SLIP JAN-2017" />
                
            
            <asp:TemplateField HeaderText="Approve">
                <itemtemplate>
                    <asp:LinkButton ID="lnkApprove" runat="server" Text="Approve" Enabled="false">
                
            
            <asp:TemplateField HeaderText="Reject">
                <itemtemplate>
                    <asp:LinkButton ID="lnkReject" runat="server" Text="Reject" Enabled="false" CommandName="RejectAddressProof">

Server Side Code:
C#
protected void MyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
            int rowIndex = gvr.RowIndex;
            

            if (e.CommandName == "RejectAddressProof")
            {

                string applicationID = "";
                string applicantName = "";
                applicationID = ((HiddenField)gvr.FindControl("hdnApplicationID")).Value;
                applicantName = ((HiddenField)gvr.FindControl("hdnApplicantName")).Value;

                //Session["applicationID"] = applicationID;
                //Session["applicantName"] = applicantName;

                //string url = "Popup.aspx?applicationID=" + applicationID + "&applicantName=" + applicantName;
                //string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
                //ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
                HiddenField hdnValue = ((HiddenField)gvr.FindControl("hdnApplicantType"));


                //Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "MyFunction('" + applicationID + "','" + applicantName + "'" + hdnValue + ")", true);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "MyFunction('" + applicationID + "','" + applicantName + "'," + hdnValue + "')", true);
            }
        }
Posted
Updated 19-Feb-17 18:27pm
v2

Google Search has plenty of examples for you: asp.net hidden field[^]
 
Share this answer
 
Comments
Member 12938448 19-Feb-17 23:38pm    
I appreciate your reply.
But i am trying to pass entire control to Javascript function and not Hidden fields value.
So can you help me how to i can send control to javascript function from server side
Graeme_Grant 19-Feb-17 23:42pm    
I am not following what you mean by "pass entire control". You would need to look it up from your client code.
Dave Kreskowiak 19-Feb-17 23:46pm    
You can't pass a "control". Because it doesn't really exist. The "controls" you're looking at in ASP.NET are just objects that only exist server side that render HTML strings the browser can render. If you want to return a "control" to add to the page (a silly thing to do IMHO), return the HTML for the "control" and the javascript would have to inject that HTML into the DOM wherever appropriate.
To pass the hidden field value
HiddenField hdnValue = ((HiddenField)gvr.FindControl("hdnApplicantType"));
     string strValue = hdnValue.Value;


To pass the Hidden Field Control, just pass the id of the control
HiddenField hdnValue = ((HiddenField)gvr.FindControl("hdnApplicantType"));
           string hdnId = hdnValue.ClientID;

           Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "MyFunction('" + applicationID + "','" + applicantName + "','" + hdnId + "')", true);

and select the control in javascript function as

JavaScript
function CallMyFunction (applicationID,applicantName, hdnId )
        {
            var hiddenControl = document.getElementById(hdnId);
            .
            .
            .
        }


Note:You cannot pass the control object directly from c#
 
Share this answer
 
v2

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