Solved

asp.net, c#, ascx

Posted on 2011-09-30
6
358 Views
Last Modified: 2012-05-12
protected void DdlTotalItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        int TotalItemCount = int.Parse(DdlTotalItem.SelectedValue);
        if (TotalItemCount >= 1)
        {
            // DdlTotalItem.Visible = true;
            MasterListItem.Visible = true;
            MasterListItemTable.Visible = true;
            for (int i = 0; i < TotalItemCount; i++)
            {

                Obout.Interface.OboutTextBox ItemTextBox = new Obout.Interface.OboutTextBox();
                ItemTextBox.ID = "TxtItem_" + i;
                ItemTextBox.Width = 150;
		DivItemCode.Controls.Add(ItemTextBox);
            }
        }
        else
        {
            MasterListItem.Visible = false;
            MasterListItemTable.Visible = false;
        }
    }

Open in new window


I have attached codes in ascx.
and now I need to get up something like

public string BuyerReferenceNo { get { return TxtBuyerReferenceNo.Text;}}

How can I do that in a For Loop? My 2nd question is: I need to read the value
on aspx. how can i carry those value from ascx?

Thanks
0
Comment
Question by:Webboy2008
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36895376
What do you mean by:
I need to get up something like

public string BuyerReferenceNo { get { return TxtBuyerReferenceNo.Text;}}

How can I do that in a For Loop?

I need to read the value on aspx. how can i carry those value from ascx?
How did you add the UserControl: via drag-drop on the designer, or via LoadControl in the code-behind?
0
 

Author Comment

by:Webboy2008
ID: 36895387
The textboxes are created in code behind.
I need to create public property in ascx
so the aspx can read it when the ascx is registered in the aspx.

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36895427
I need to create public property in ascx
so the aspx can read it when the ascx is registered in the aspx.
Then what you posted:

public string BuyerReferenceNo { get { return TxtBuyerReferenceNo.Text;}}

Open in new window


should work just fine. I've in fact done something quite similar in a project I am working on.
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:Webboy2008
ID: 36895436
yes. let me explain more.

Just assume you have a dropdown with number 1 to 5
if you select 5, 5 city textboxes will be created in the code behind.
then our next code is to create get/set

public string city { get { return txtcity.text}}

however, now I have 5 or less, how can i do that?
and when the ascx is registered on the aspx

how can i retreive the value from the ascx?
0
 
LVL 5

Accepted Solution

by:
AlokJain0412 earned 500 total points
ID: 36895988
Following is the code sample  for fetch the value from .ascx
   
protected void Page_Load(object sender, EventArgs e)
{
        Control uc = LoadControl("WebUserControl1.ascx");
        uc.ID = "MyControl";
        this.PlaceHolder1.Controls.Add(uc);
}
protected void Button1_Click(object sender, EventArgs e)
{
        TextBox tb = (TextBox)this.Page.FindControl("MyControl").FindControl("TextBox1");
        if (tb != null)
        {
            string str = tb.Text;
        }

}

Where "MyControl" is the UserControl ID and "TextBox1" is the ID of the TextBox control that resides in the UserControl

Cheers
0
 

Author Comment

by:Webboy2008
ID: 36898519
AlokJain0412: please read my original question. I have more than 1 textbox....
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question