Solved

asp.net, c#, ascx

Posted on 2011-09-30
6
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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