locked
Hidden field not showing value RRS feed

  • Question

  • User-797751191 posted

    Hi

     In the below code Hidden field not showing value but in labels value is correct. In Display function Hidden fields show correct value.

    in btnApprove_Click in InvoiceNo it shows correct value but in Hidden field it shows "".

    protected void Display(object sender, EventArgs e)
        {
            LinkButton lnkbtn = sender as LinkButton;
            GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
    
            hdf_UrlLink0 = (gvrow.FindControl("hdfUrlLink") as HiddenField);
    
            lblLocationId.Text = gvrow.Cells[2].Text.ToUpper().Trim();
            ClientScript.RegisterStartupScript(this.GetType(), "Pop", "ApproveReject();", true);
        }
    
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                HiddenField hdf_UrlLink = hdf_UrlLink0;
                string InvoiceNo = lblInvoiceId.Text;
    }
    }

    <div class="modal-footer">
    <asp:HiddenField ID="hdf_UrlLink0" runat="server" />
    <asp:Button ID="btnApprove" OnClick="btnApprove_Click" runat="server" Text="Approve" CssClass="btn btn-primary" />
    </div>

    Thanks

    Friday, September 27, 2019 5:13 AM

All replies

  • User288213138 posted

    Hi jsshivalik,

    in btnApprove_Click in InvoiceNo it shows correct value but in Hidden field it shows ""

    HiddenField hdf_UrlLink = hdf_UrlLink0;

    In the btnApprove_Click event, you only instantiated a HiddenField, It doesn't set any values.

    What do you want to do? Please don't give us a few words and let us guess your thoughts.

    Best regards,

    Sam

    Friday, September 27, 2019 6:48 AM
  • User-797751191 posted

    Hi

      In display function i have written like below . Is it ok . I wanted when in display ApproveReject() hiiden field must have value.

    hdf_UrlLink0.Value = Convert.ToString((gvrow.FindControl("hdfUrlLink") as HiddenField).Value);

    Thanks

    Friday, September 27, 2019 6:55 AM
  • User288213138 posted

    Hi jsshivalik,

    I wanted when in display ApproveReject() hiiden field must have value

    ClientScript.RegisterStartupScript(this.GetType(), "Pop", "ApproveReject();", true);

    This code will call the js method ApproveReject(), Do you want to set HiddenField value by this method?

    If so, please post you js function ApproveReject().

    Best regards,

    Sam

    Friday, September 27, 2019 7:27 AM
  • User753101303 posted

    Hi,

    For now there is nothing in your code showing how you populate this form field and how you read back its value. If the filed is really empty, then double check how you populate this value.

    If done using JavaScript I suspect you are not using the correct client side id control,

    Friday, September 27, 2019 7:42 AM
  • User-797751191 posted

    Hi Samwu/Patrice

    protected void Display(object sender, EventArgs e)
        {
            LinkButton lnkbtn = sender as LinkButton;
            GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
    
            hdf_UrlLink0 = (gvrow.FindControl("hdfUrlLink") as HiddenField);
    
            lblLocationId.Text = gvrow.Cells[2].Text.ToUpper().Trim();
            ClientScript.RegisterStartupScript(this.GetType(), "Pop", "ApproveReject();", true);
        }
    
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                HiddenField hdf_UrlLink = hdf_UrlLink0;
                string InvoiceNo = lblInvoiceId.Text;
    }
    }
    
    <div>
                                    <div class="modal fade" id="ApproveModal" role="dialog">
                                        <div class="modal-dialog" style="width: 360px;">
                                            <div class="modal-content">
                                                <div class="modal-header" style="background-color: #337AB7;padding:5px;color:#FFF;border-bottom:2px dashed #337AB7;">
                                                    <button type="button" class="close" data-dismiss="modal">
                                                        &times;</button>
                                                    <h4 class="modal-title">Reason for Reject/Approval</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <div class="form-group">
                                                        <div class="row">
                                                            <div class="col-sm-4">
                                                                <asp:Label ID="lblInvoice" runat="server" Text="Invoice No" class="control-label"></asp:Label>
                                                            </div>
                                                            <div class="col-sm-8">
                                                                <asp:Label ID="lblInvoiceId" runat="server" Text="" class="control-label"></asp:Label>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="modal-footer">
                                                    <asp:HiddenField ID="hdf_UrlLink0"  runat="server" />
    
                                                    <asp:Button ID="btnApprove" OnClick="btnApprove_Click" runat="server" Text="Approve"  CssClass="btn btn-primary" />
                                                    
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
    
    function ApproveReject() {
                    $('[id*=ApproveModal]').modal('show');
                }

    Thanks

    Saturday, September 28, 2019 6:11 AM
  • User409696431 posted

    What code do you think is setting the hiddenfield's value?  I don't see it in what you posted.

    hdf_UrlLink0.Value = "the value you want";

    And what are you intending to do with this code?

    HiddenField hdf_UrlLink = hdf_UrlLink0;

    Saturday, September 28, 2019 7:24 AM
  • User-797751191 posted

    Hi Kathyw

       Where & how i should assign a value

    Thanks

    Saturday, September 28, 2019 2:11 PM
  • User475983607 posted

    Where & how i should assign a value

    I'm a little confused.  This is your design.  You should know where and when the hidden field must be assigned a value.  How can the community know your intent?

    Secondly, this thread looks similar to your other posts where you are trying to pass values to a modal.  In the previous threads the community provided working code that illustrates how pass values to a modal.   Can you explain why you are not following the recommendations and continue to use the same approach that clearly does not work?

    Saturday, September 28, 2019 2:30 PM
  • User409696431 posted

    I've already shown you how to assign a value.  See my example in my response, assuming the HiddenField you are talking about is the one with ID hdf_UrlLink0.

    hdf_UrlLink0.Value = "the value you want";

     When and where to assign it is your issue: where and when you need to.

    Saturday, September 28, 2019 3:39 PM