values of web controls in user control can not be access from other pages???

I have aspx page(brief code: includes ascx file)

<%@ Register Src="reseller.ascx" TagName="reseller" TagPrefix="uc1" %>

<

form id="form1" runat="server">

<

uc1:reseller ID="idreseller" runat="server" />

</form>

the code for asxc file . i have the PostBackUrl to reseller.aspx

<

asp:TextBox ID="txtPostCode" runat="server" CssClass="form1" Width="50" MaxLength="4" />

<

asp:ImageButton ID="ibtn"  ImageUrl="images/searchbutton.jpg" PostBackUrl="~/reseller.aspx" runat="server"  />

In my reseller page i try to read the post value of control txtPostCode from the previous aspx page.; but the value is always null(error message: Object reference not set to an instance of an object). Can anyone pls explain why this is happening.

Note: works fine if i add the textbox and imagebutton control directly to the aspx page(not using asxc)

if(!page.ispostback)

{

    label1.text=Request.Form["txtPostCode"].ToString();

}

0
ans_anish
12/5/2006 6:00:18 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
938 Views

Similar Articles

[PageSpeed] 43

 

Hi,

When you try to access a control available in the Usercontrol, you need to do a little bit of work around.

I have an article which discusses on how to access the Dropdownlist Selected Value, present in the usercontrol http://harishmvp.blogspot.com/2004/07/selected-item-in-dropdownlist-in.html


regards,
Harish

http://geekswithblogs.net/ranganh
0
ranganh
12/5/2006 6:59:36 AM

 

Sorry, this is the duplicate post which happened by mistake.

 THIS CAN BE DELETED


regards,
Harish

http://geekswithblogs.net/ranganh
0
ranganh
12/5/2006 6:59:48 AM

but how you accessthe web control  in the receiving page, when you are using PostBackUrl .

And the receving page have the code

Request.Form["name of the web control"]

0
ans_anish
12/5/2006 10:47:01 AM

hi,

you can add <%@ PreviousPageType VirtualPath ="previousPage.aspx"  %> to the reseller.aspx

and then in reseller.aspx use

 TextBox t=(TextBox )(PreviousPage.FindControl("WebUserControl1").FindControl("TextBox1"));

 to referece the textBox in the WebUserControl

the following is my sample code

my first page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>

  <form id="form1" runat="server">
    <div>
                  <uc1:WebUserControl ID="WebUserControl1" runat="server" />
   
    </div>
    </form>

my second page

<%@ PreviousPageType VirtualPath ="~/Default3.aspx"  %>

 protected void Page_Load(object sender, EventArgs e)
    {
        TextBox t=(TextBox )(PreviousPage.FindControl("WebUserControl1").FindControl("TextBox1"));

        TextBox1.Text = t.Text;
    }

hope it helps

0
jessjing
12/6/2006 5:34:51 AM
Reply:

Similar Artilces:

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Single page with multiple user web controls VS Multiple page with specific user web controls
I have a question regarding single page with multiple user web controls vs multiple page with specific user web controls   Option 1: I am of the opinion to have multiple pages with specific user web controls and use an object to store all the information as the user navigates through the application. And finally at the end, read this object and save all the information to the backend database.   Option 2: My respected team member suggests that we have only one page, with all the specific user web controls and not use an object, instead show/hide the user web controls based ...

Accessing server control values of a web user control from ASPX page
Hi, I have created a web user control (ascx) page with several server controls and the web user control included in a aspx page. I have a command button in main aspx page. How can I access values of the controls in web user control from onclick event of the aspx page. Thanks, Chamil. Make the controls on the web user control public.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Could you pl. give me a sample line of code on how to make the control public. thanks, chamil Are you developing inline or with a code-behind?...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

How can I control load sequence of web controls in a web page?
Hi, How can I control load sequence of web controls in a web page? Thanks. For the most part, the load sequence on a web page is not relevant since all controls must be present before the page can be used. Could you provide more information as to what you're trying to do?Christopher Reed"The oxen are slow, but the earth is patient." Hi, As far as I know, we have no luck to control the load order of the Web controls on a page. However, if we need to load some controls under given conditions, we can achieve this by adding them dynamically instead.Forwa...

controlling an object in a web control from the page the web control is placed in
I have created a web control in vb.net that has an image button and an image. when it loads the image button is visible and the image is not. I want to be able from the page which "includes" the web control to set the image button to invisible and the image to visible. When I tried this, the main page didn't recognise the image button or the image (both < asp: objects). help would be gratefully appreciated. oh yeah, it's inline code so any code behind stuff will just confuse me ;) Some code please.-- Justin Lovell...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

How do you access controls within a web user control from another page?
Hi guys/girls. Say for instance you have a web user control with 2 textboxes in it - txtBoxFirstname and txtBoxSurname. I place this web user control on a page. How do I access those controls from that page? Thanks guys this.Findcontrol("UserControlName"); Hi,You can make two properties on the user control that will expose the Text property of the textboxes and then from the page you'll be able to use them.For example in the user control:public string Text1{   get   {       return Textbox1.Text;   }   s...

Web resources about - values of web controls in user control can not be access from other pages??? - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Venezuela's Opposition Wins Control of Legislature - Al Jazeera America
The opposition won at least 99 seats in Venezuela's 167-seat legislature, in a major setback for President Nicolas Maduro

The ACLU backs using the terror watch list for gun control, but only “with major reform”
... did say, through a spokesperson, that the watch list would need “major reforms” in order to be used as an effective tool for gun control and ...

With gun control off-limits, politicians want tech sector to fight terror
... very next day, the Senate voted against a measure that would have barred gun sales to people on federal terror watchlists. Another gun-control ...

Obama calls for better gun control, and for tech companies to help fight terrorism
President Barack Obama all but called out encryption in a 15-minute Address to the Nation speech on Sunday night. The President touched on various ...

Obama speaks on ISIS, gun control, tolerance in Oval Office address - Videos - CBS News
In a primetime speech Sunday night, President Obama said the terror attack in San Bernardino, California, shows terrorism is now in a new phase. ...

Porsche To Mission E Control: We Are Clear For Launch!
... handling of a Porsche. The contrast seemed to start early cries of the Mission E being the next Tesla [&hellip Porsche To Mission E Control: ...

Windows 10 vs. OS X: Which gives sys admins more control?
Nearly everything can be managed as if it were a mobile device, using APIs at the operating system for assured reach and consistent implementation ...

NV's Fiore: 'That 5 Year Old Grandson Of Mine Has Total Trigger Control'
It's very likely you've seen Michele Fiore's family Christmas photo by now, it's been all the rage at Idiocracy viewing parties everywhere. If ...

The Solution Isn’t As Simple As Gun Control
... latest column over at the Daily Beast details how, in the wake of the San Bernardino shootings, Democrats were quick to pounce on the gun control ...

Resources last updated: 12/8/2015 3:35:39 PM