Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net, c#, ascx

Posted on 2011-09-30
6
Medium Priority
?
366 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
Technology Partners: 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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