Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:02:02+00:00 2026-05-26T01:02:02+00:00

First off, forgive my English. I created one user control with Textbox and AutoCompleteExtender

  • 0

First off, forgive my English. I created one user control with Textbox and AutoCompleteExtender controls, and it’s working fine. Now, I wanted to reflect my textbox similar to a dropdownlist. When i kept the user control in a GridView and accessed the value through a hidden field, i’m getting “0” value. How can i read hidden field value in my page?

UserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" Code File="UserControl.ascx.cs"
    Inherits="UserControl" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 

<script type="text/java script">
    function DispValue(sender, e) {
        alert(e.get_value() + "   : user control");
        document.getElementById(hiddenFieldName.Client ID).value = e.get_value();       
    }
     </script> 
<asp:Hidden Field ID="hdnValue" runat="server" Value="0" /> 
<asp:Text Box ID="txtName" runat="server" Text=""> </asp:Text Box> 
<cc1:AutoCompleteExtender ID="ACEName" TargetControlID="txtName" runat="server"
        CompletionInterval="10" MinimumPrefixLength="1" Service Method="Get Name"
        Service Path="UserControlWebServices.asmx" OnClientItemSelected="DispValue">      
</cc1:AutoCompleteExtender>

UserControl.ascx.cs

public partial class UserControl : System.Web.UI.UserControl 
{    
    protected void page_load(object sender, EventArgs e)
    {
        ACEName.ContextKey = "1";
    }

    public String SelectedValue
    {
        get { return this.hdnValue.Value; }
    }

    public String SelectedText
    {
        get { return this.Name.Text; }
    } 
}

MyAspxPage.aspx

<%@ Register Src="~/UserControl.ascx" TagPrefix="puc" TagName="UserControl" %> <head runat="server">
    <title></title> </head> <body>
    <form id="form1" runat="server">  
    <asp:Script Manager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:Script Manager>
    <asp:Grid View ID="gvPatient" runat="server" AutoGenerateColumns="false" OnDataBound="GridPatient_DataBound">
        <Columns>
            <asp:Template Field>
                <Header Template>
                    Patient Name
                </Header Template>
                <Item Template>
                    <puc:UserControl ID="pucPatient1" runat="server" />
                </Item Template>
            </asp:Template Field>   </Columns>
    </asp:Grid View>
    <asp:Button ID="btnSave" runat="server" OnClick="Save" Text="Save" OnClientClick="return StartUpload();" />
    </form> 
  </body> 
</HTML>

MyAspxPage.cs

    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dt = new DataTable();
            dt.Columns.Add("col1");
            dt.Columns.Add("col2");
            dt.Columns.Add("col3");
            dt.Columns.Add("col4");
            dt.Columns.Add("col5");
            dt.Columns.Add("col6");


            if (Session["dt"] == null)
            {
                dt = AddRow(dt);
                gvPatient.DataSource = dt;
                gvPatient.DataBind();
                Session["dt"] = dt;
                //ViewState["dt"] = dt;
            }
            else
                dt = (DataTable)Session["dt"];//ViewState["dt"];

        }
    }

    private DataTable AddRow(DataTable dt)
    {
        for (int i = 0; i < 5; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "";
            dr[2] = "";
            dr[3] = "";
            dr[4] = "";
            dr[5] = "";
            dt.Rows.Add(dr);
        }
        return dt;
    }

 protected void GridPatient_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow item in gvPatient.Rows)
        {
            UserControl ptuc = (UserControl)item.FindControl("pucPatient1");
            string id = ptuc.SelectedValue;
         }
    }

 public void Save(object sender, EventArgs e)
    {
        foreach (GridViewRow item in gvPatient.Rows)
        {
            if (item.RowType == DataControlRowType.DataRow)
            {
                UserControl ptuc = (UserControl)item.FindControl("pucPatient1");
                string id = ptuc.SelectedValue;//getting null value.
                string patientName = ptuc.SelectedText;
             }
        }    }

this is all what i did.

i’m stuck with this please help me.

Sharanamma

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:02:03+00:00Added an answer on May 26, 2026 at 1:02 am

    Hi friends
    Thanks for your valuable reply,
    actually its working fine, but small change in UserControl
    clientselected event side,i,e

    UserControl.ascx function DispValue(sender, e) {
    var source = sender.get_id();
    var lastIndex = source.lastIndexOf(“_”);
    var replaced = source.substring(0, lastIndex + 1);
    var hdnId = replaced + “hdnPatientNumber”;
    document.getElementById(hdnId).value = e.get_value();
    }

    UserControl.ascx.cs
    public String SelectedValue
    {
    get { return Request.Form[this.hdnPatientNumber.UniqueID];
    }
    }

    Thanking you all,
    regards,
    Sharanamma.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, forgive my English, my attempt, I am creating a autocomplete user control,
First off, I'm working on an app that's written such that some of your
First off, forgive me if this is a schoolboy question :) We have a
First off, please forgive the stupidness of this question but Im not from a
First off, my problem is quite similar to this one . I would like
First off, the jQuery datepicker works fine with classes when doing a fresh page
First off: Everything works , but I would like to fine tune this a
First off I've never posted any questions like this before so forgive any faux
First off I've been working with Java's Concurrency package quite a bit lately but
Please forgive me if I don't explain this very well. First off, I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.