.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Usercontrols value on page_init

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net

Hello, In one of my pages I use an usercontrol. The usercontrol has a textbox and a button on it.

When someone adds text to the usercontrols textbox, I want to use the entered text in my page_init event.

The problem is that in the page_init event, the textbox value is empty. How can I use the entered text in the page_init event?

Best regards

View Complete Post

More Related Resource Links

Ajax/Jquery code on UserControls

Hello,I have some user controls where I would like to add some javascript that uses Ajax and Jquery technology. Also these scripts should use Sys.WebForms.PageRequestManager.getInstance().add_endRequestand other functions of the Ajax framework.In the past I have added the related code to the hosting aspx page but it becomes a problem when re-using the same control in multiple aspx.Which are the best practice to follow in this case?Regards

Convert Displayed UserControls like Gridview to PDF

Hi, Can anyone tell me how to convert UserControl to PDF and save it in Silverlight . For Example: I have a page where it has some TextBoxes and Gridview. Whenever i click on a button called "Print to PDF", I want the whole page converted to PDF and Saved.

Javascript in UserControls

Hi, I am making a few usercontrols that have javascript functionality. The javascript is contained within an external .js and I current link to it in my .ascx file.  <script language="javascript" type="text/jscript" src="../Javascript/CollapseDIV.js"></script>   I have two problems here:   1- This only works if the parent web form is in the implied location - down one folder level 2 - If I use the usercontrol more than once on the same page the javascript file is linked in x times.   Can anyone advise the correct way to use javascript functionality in a usercontrol where the javascript is contained in an external file? I assume the asp.net server controls do not copy in their javascript x times so I don't want mine to either.   Thanks   Andy  

Adding multiple usercontrols dynamically


Hi all,

I have a simple user control which contains a textbox and a dropdownlist. I need to add this control multiple times to my page then save the details to my db, validating each control. When they re-enter my page I need to load the user control for each record in the db populated with the data they entered. They can then edit the data, delete the row or add new rows.

I'm trying to find the cleanest most efficient way to accomplish this. I realise I would need to re-add the user controls after each postback re-populating the data. Would the best way be to add each row to an arraylist or list of type object, save it to the viewstate and re-add the controls with data on postback, or is there another method which would suit?

I've looked high and low but can't find anyone with a similar problem/solution. 

Any help is much appreciated,



protected void Page_PreInit(object sender, EventArgs e)



protected void Page_Load(object sender, EventArgs e){}

i have these two functions with code in them i placed a breakpoint at the page_Preinit   but when i run the application it does not enter the breakpoint.


Page_Init firing on each postback


I am having a problem with web pages in a .Net site where the Page_Init is firing on each postback rather than the normal behavior (Page_Init fired initially, and only Page_Load fired on postbacks)

Several comments:

1.  AutoEventWireup is set to false on all pages, with a "Handles Me.Init" set on Page_Init.  All events are defined with the "Handles" verb as shown below

2.  Each web page is subclassed to a parent class which provides strongly-typed access to the contents of session variables.

3.  The Page_Load event for most of the pages performs a DataBind operation on a gridview control.

Partial Public Class SamplePage
    Inherits PageManager (PageManager inherits from System.Web.UI.Page)

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init


    End Sub

Any ideas?

sharepoint webparts/Usercontrols



i have to create a search box which searches from external database(say oracle) and displays results in  a grid

Next (second level)  In the results displayed clicking on one field(say prcode) it should display corresponding child records from sql server database and

next when i select a record from results the detailed information need to be displayed in a form view which can be edited.

what approach should i follow on creation of this?(best approach)

any code samples would be appreciated.


Webparts and usercontrols


I got a usercontrol whch I want to add to a webpart.

The usercontrol contains a code behind file with various logic in it.

My questions are:
- how do i embed my usercontrol into a webpart ?
- should the logic from the usercontrol be in the web part .cs file or stay in the usercontrol's codebehind file ?




hello ,

  I want to know what the differnce when deploy  .ascx file on  "CONTROLTEMPLATES"  and  deploy it on "UserControls" folder in Virtual directory folder.




Finding UserControls within a PlaceHolder control



I am having problems finding my UserControls inside the Controls collection of a Placeholder control.  

I have a ListView control with a PlaceHolder control in its ItemTemplate. OnItemdataBound for the ListView control I am adding a custom UserControl to the Controls collection of the Placeholder control. It all renders fine. My problem is when I try to find my user controls in the Placeholder. I just can't get it back. My code is below.

My objective here is to get to the input controls within my UserControl and call the save method of this. Please help.

PlaceHolder intakeBenefitHolder = null;
protected void lvIntakeBenefits_ItemDataBound(object sender, ListViewItemEventArgs e)
 if (e.Item.ItemType == ListViewItemType.DataItem)
  using (ListViewDataItem item = (ListViewDataItem)e.Item)
   // cast the ListViewDataItem to a Benefit
   Benefit benefit = (Benefit)item.DataItem;
   // create the ClientIntakeBenefitDictionary dictionary for the benefit and add it to the BenefitAtIntake control
   ClientIntakeBenefitDictionary dictionary = new ClientIntakeBenefitDictionary(benefit, new Guid(this.ContactId));

   // Create the IntakeBenefit

adding usercontrols dynamically to custom control


I have one custom control which inherits from composite control ,i want to  load an usercontrol(.ascx) dynamically with in that custom control and render it to an aspx page

How can  i do that please help me out

Accessing variables containing usercontrols in a partial class


Hello everyone,

Last night you guys here on this forum helped me in accessing properties of a dynamically loaded UC in an aspx page. Now i am facing another hiccup.

My code behind is : public partial class SiteUserControls_Message_Messages : BaseControl

In one of the click events i am loading three web users controls:

protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)

         SiteUserControls_Message_Create CreateNewMessageUC = Page.LoadControl(CreateMsgControl) as SiteUserControls_Message_Create; // typecasting the UC


Now i want to access this variable CreateNewMessageUC in another event like this:

protected void MarkAsUnreadLinkButton_OnClick(object sender, EventArgs e)




In My effort to make the UC variable global i have put that in class body liek this

public partial class SiteUserControls_Message_Messages : BaseControl

       SiteUserControls_Message_Create CreateNewMessageUC;


But when i access teh variable in another event i

Resource Loading Problem (2 UserControls, 1 Load works, 1 Fails. Both UserControls and the Resource


I am having an issue where I have 2 WPF UserControls loading a PNG file from codebehind, the png loads fine in one UserControl, but fails in the other.


This is the top of the codebehind for the UserControl that works...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.ComponentModel;

using ModuleInterface;
using System.Reflection;
using System.Windows.Threading;

blend going fail to open Xaml page with more UserControls in silverlight


Hello Everybody ! Many years going but No one can give perfact solution to open Xaml file with more usercontrol in expression blend. nay one



its not more useful I want 100 % .please  reply



Show UserControls with JavaScript-Code



I look for a solution to solve my problem in programming a ASP.NET-Application. In the following I write my assignment, what I have done and my current problems.

I want to create a Application which have a TreeView and a Image. The TreeView-Objects should have Drag&Drop for dragging the objects to the image. When I drag the objects on image, the position and the ID of the object should write to database. At last, the object on the image have to show as a own UserControl.

Have Done:
The Drag&Drop with the TreeView works (Place the image to a div-element). Database-Writting works.

The problem is to creating a new UserControl-Element after Dragging the object to the image.

Can anyone help me, how I should do???????


Mulitple forms, hidden panels, add and remove usercontrols or...?

Need to build a touchscreen app whose menus take up half the screen.  As you make choices the menu area changes to the next set of menus, and so on.  Would you recommend using panels with the menus and turning them visible/not visible.  Using numerous forms, or use usercontrols and add and remove them as needed?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend