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

  • SEARCH
  • Home
  • 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 6597151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:10:18+00:00 2026-05-25T18:10:18+00:00

First off, forgive my English, my attempt, I am creating a autocomplete user control,

  • 0

First off, forgive my English, my attempt, I am creating a autocomplete user control, to replace drop downs, I have created the user control, and its working fine. Now for simplicity sake, I need to provide a public property in my User Control to get the selected id, similar to the SelectedValue of the DropDrown control. I’m stuck with this, any ideas will be appreciated.


Hi My Code

UserControl.ascx

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

function DispValue(sender, e) {
alert(e.get_value() + ” : user control”);
document.getElementById(hiddenFieldName.Client ID).value =
e.get_value();
}

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” %>

Patient Name

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.

Thanking You, cheers 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-25T18:10:19+00:00Added an answer on May 25, 2026 at 6:10 pm

    Probably you are using the TextBox control in background for your Autocomplete. So, define the SelectedValue as following:

    public string SelectedValue
    {
       get { return this.textBox.Text; }
    }
    

    Or if you need the ID of the selected value, not display text, then place HiddenField near your TextBox and populate the ID of selected value from autocomlete using JavaScript. And the use it on the server side:

    public string SelectedValue
    {
       get { return this.hiddenField.Text; }
    }
    
    • 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. I created one user control with Textbox and AutoCompleteExtender
First off, forgive me if this is a schoolboy question :) We have a
First off, let me clarify the platforms we are using. We have an ASP.NET
First off, I'm aware this is a bad practice and I have answered many
First off, please forgive the stupidness of this question but Im not from a
First off, please accept my apologies if this question is basic, I mainly have
First off, I am not a Unix expert by any stretch, so please forgive
First off I have sort of been tossed off in the deep end on
First off let me say this is my first ASP.NET project I have done.
First off, I'm using Access 2000 and DAO. I have code that executes a

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.