Solved

asp.net, c#, ascx

Posted on 2011-09-30
6
345 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Webboy2008
Comment Utility
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
Comment Utility
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
Comment Utility
AlokJain0412: please read my original question. I have more than 1 textbox....
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now