Solved

asp.net, c#, ascx

Posted on 2011-09-30
6
362 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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