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


Top 5 Contributors of the Month
david stephan
Post New Web Links

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender when a user

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
 
I have a application which uses webparts and 1 control is also a Script Control. So my user controls are derived from System.Web.UI.WebControls.WebParts.WebPart which makes them webparts. I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine. Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application. That control is also a script control so it inherits from System.Web.UI.WebControls.WebParts and also implement IScriptControl So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous. And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this: Protected Overrides Sub OnPreRender(ByVal e As EventArgs) If Not Me.DesignMode Then Me.isloaded = True ' Test for ScriptManager and register if it exists sm = ScriptManager.GetCurrent(Page) If sm Is Nothing Then _ Throw New Ht


View Complete Post


More Related Resource Links

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender and CreateCh

  

 I have a application which uses webparts.

So my user controls are derived from System.Web.UI.WebControls.WebParts which makes them webparts.

I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine.

Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application.

So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous.

And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this:

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

If Not Me.DesignMode Then

Me.isloaded = True

' Test for ScriptManager and register if it exists

sm = ScriptManager.GetCurrent(Page)

If sm Is Nothing Then _

Throw New HttpException("A ScriptManager control must exist on the current page.")

user control derived from System.Web.UI.WebControls.WebParts only fires its OnPreRender and CreateCh

  
I have a application which uses webparts. So my user controls are derived from System.Web.UI.WebControls.WebParts.WebPart which makes them webparts. I have everything setup and working fine as far as the personalization and webpart goes... every thing displays and works fine. Except that 1 of my control needs to do a bit of work in the OnPreRender event and it turns out that event only gets fired when a user is loged in the application. That control is also a script control so it inherits from System.Web.UI.WebControls.WebParts and also implement IScriptControl So lets imagine that an administrator while logged in switched to 'Sharedscope' within the webpartmanager and then has added the usercontrol/webpart 'calendar' to the top webpart zone. This then makes the 'calendar' control viewable by all and any user who visits the page wheter logged in or anonymous. And this works fine and very well as it is supposed to. However in the 'Calendar' user control which is derived from System.Web.UI.WebControls.WebParts I have an overiden 'OnPreRender' event like this: Protected Overrides Sub OnPreRender(ByVal e As EventArgs) If Not Me.DesignMode Then Me.isloaded = True ' Test for ScriptManager and register if it exists sm = ScriptManager.GetCurrent(Page) If sm Is Nothing Then _ Throw New HttpException("A ScriptManager contro

Choosing Between a User Control or Web Part for SharePoint

  
SharePoint will only display Web Parts on a page. However, there are publicly available shims that allow you to write user controls and have them be displayed as a Web Part. From SharePoint's point of view, the shim is a Web Part. From the point of view of the user control, the shim is simply a control in .NET that is including the user control

Building Re-Usable ASP.NET User Control and Page Libraries with VS 2008

  

I am having problems with a user control. I want my solution to have a separate project for holding my user controls.


The main project can get a reference to this user control project and can import this user control dll into my main project. 


Thanks in advance,

Dheeraj Mittal

dhemittal@gmail.com


Multiple Instances of User Control

  

I have a user control that I place on a page severl times.  When I make a selection on a ddl in one one control the SelectedIndexChanged event fires for all the control on the page for that ddl.  So I get duplication of an insert that I do.  Is there a way to make sure these events are isolated so this doesn't happen.

Thanks,


how to get an array of all the asp.net textbox control inside create user wizard control?

  

Hi,

How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {
                    oldonload();
                    func();
                }
            }
        }


        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                }
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";
                }
            }
        }
        addLoadEvent(prepareInputsForHints);

    </script>


 

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
       

Persist data in a dynamically populated ListBox in a user control

  

Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)

{

       If(!IspostBack)

        {

              listBox.items.Add("Item1");

             listBox.items.Add("item2");

             listBox.items.Add("item3");

         }

}

 

My Click Function

Protected Void Button1_Click(object sender, EventArgs e)

{

       string strValue = listBox.SelectedValue

}

 

I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Category attribute of user control property does not work correctly in categories tab.

  

Hi,

I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".

[Category("Styles"), DefaultValue(""), Description("The value for formating something.")]
public String MyFormatProperty
{
set { /* the code for set */; }
get { /* the code for get */; }
}

And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.

Does anybody know why? How can I display the category correctly only with set?

Thanks, S.



OnItemCommand not firing in Templated User Control

  

I have a templated user control with single instance template attribute. It works great for everything except the following scenario:

<ntc:Box>
 <ContentTemplate> 

    <asp:UpdatePanel ID="upDirectoryBrowser" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="fsBrowser" EventName="FolderSelected" />
        <asp:AsyncPostBackTrigger ControlID="flsBrowser" EventName="FileSelected" />
        <asp:AsyncPostBackTrigger ControlID="flsBrowser" EventName="LinkSelected" />
    </Triggers>
    <ContentTemplate>                              
        <table width="100%">
            <tr>
                <td style="width: 230px;">                        
                    <ntc:FolderSelector ID="fsBrowser" runat="server" OnFolderSelected="fsBrowser_FolderSelected"
                    OnControlException="fsBrowser_ControlException"  /> 
                </td>
                <td>
                    <ntc:FileSelector ID="flsBrowser" runat="server" OnFileSelected="flsBrowser_FileSelected"
                    OnControlException="fsBrowser_ControlException" O

"Type ASP.x is not defined" error for dynamic user control when publishing updateable

  

I have a user control (ContainerCtrl) which programmatically instantiates another user control (SimpleCtrl) in OnLoad. It builds and runs fine, but when I publish it I get the error "error BC30002: Type 'ASP.SimpleCtrl' is not defined." (If I publish without the "updateable" option there's no error, but I need the site to be updateable.)

I assume this has to do with the particulars of how the assembly(ies) are built for the different compiler options. My question is, how can I get it to work properly for "updateable" publishing?

VS 2008 / .NET 3.5 sp1

The code follows (web.config is the default from Visual Studio).

Many thanks, Dave

SimpleCtrl.aspx------------------------------

<%@ Control Language="VB" ClassName="SimpleCtrl" CodeFile="SimpleCtrl.ascx.vb" Inherits="_SimpleCtrl" %>

<div>
    Simple control
</div>

SimpleCtrl.aspx.vb------------------------------

Partial Class _SimpleCtrl
    Inherits UserControl

    'Nothing to see here.

End Class

ContainerCtrl.aspx------------------------------

<%@ Control Language="VB" CodeFile="ContainerCtrl.ascx.vb" Inherits="_ContainerCtrl"

Least Privilege: Teach Your Apps To Play Nicely With Windows Vista User Account Control

  

User Account Control in Windows Vista keeps the OS safe from intentional and accidental configuration changes.

Chris Corio

MSDN Magazine January 2007


GDI+: A Primer on Building a Color Picker User Control with GDI+ in Visual Basic .NET or C#

  

Although most developers and APIs use the RGB scheme when working with colors, it's not the only available way to represent or select colors. For instance, the standard Windows color-selection dialog box allows you to work with the HSL color scheme in an indirect way. In this article, the author describes several color selection schemes, and uses GDI+ (via the System.Drawing namespace) to create a component that makes it possible for your own applications to provide a simpler, friendlier color chooser. Along the way, you'll get tips to help you use GDI+ in your own apps.

Ken Getz

MSDN Magazine July 2003


Passing Primary Key to User Control to Display Record Detail

  

I'm building a user control to display detail information on a parent record. The user control will be displayed via an Ajax Modal Popup. The user control works and is displayed when expected. The problem that I'm having is that I'm not able to pass in the primary key for the parent. The control is displayed via the _ItemCommand event of a Repeater. In the markup for the user control, I explicity set the ContactId to 0 to avoid an error when the control loads (its still underdevelopment, eventually that I'll check if the value is valid).

I was assuming that I could change the property in the _ItemCommand event, but obviously its not working.

In the Page_Load event this code successfully sets the ContactId property of the control. The _ItemCommand event appears to set the value. However when I set a test label on the user control to the Me.ContactId, its showing '0' as if it was never passed in.

        UserControlContactDetail.ContactId = "1462"
        test.Text = UserControlContactDetail.ContactId


    Protected Sub RepeaterDirectory_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles RepeaterDirectory.ItemCommand

Protected Sub RepeaterDirectory_ItemCommand(By

Rendering User Control content

  

I have a scenario where, the content is:
<div>
 ASP.NET Controls
      User Control
 ASP.NET Controls
</div>

The entire div code is rendered and is sent at a mail using the code:

Dim sw As New StringWriter()
Dim w As New HtmlTextWriter(sw)
Dim s As String = sw.GetStringBuilder().ToString()
dvContent.RenderControl(w)


This works fine except that the User Control does not get rendered.

Any way out, so that the User Control content is also rendered ?


asp expression bound to user control parameter?

  

How can I get pass the DataKey of a GridView to a usercontol, preferably without code behind.


Why doesn't this work:

<ucOrderDetails:AJAX_OrderDetail ID="od1" runat="server" OrderNumber='<%# GridView1.SelectedValue.ToString() %>'  />

GridView1 is just a list of orders with a DataKey of OrderNumber.

od1 is not inside of a databout control, does it need to be?


Dynamically load user control without postback

  

Hi all,

I need urgent help. (c#coding)

In my base page, I have a dropdownlist control which loads different usercontrols on selectedindexchanged event.

While loading these usercontrols, my page postbacks all the page. I used updatepanel but again same problem.

Is there any way to load controls without postback? I Really need help as soon as possible.

Here is my code:

protected void Page_Init(object sender, EventArgs e)
    {
        if (Session["control"] != null)
        {
            string c = Session["control"].ToString();
            if (c == "1")
            {
                iuc = (IlkogretimUC)LoadControl("~/Controls/Ilkogretim.ascx");
                dl.SelectedValue = Session["control"].ToString();
                ph.Controls.Add(iuc);
                //UpdatePanel2.ContentTemplateContainer.Controls.Add(iuc);
            }
            else if (c == "2")
            {
                luc = (LiseUC)LoadControl("~/Controls/LiseUC.ascx");
                dl.SelectedValue = Session["control"].ToString();
                ph.Controls.Add(luc);
            }
            else if (c == "3")
            {
                youc = (YuksekokulUC)LoadControl("~/Controls/Yuksekokul.ascx");
                dl.S

Knowing the event occured in user control in current page

  

Hello,

 

      My web application has user control which uses third party controls called Devexpress controls. The user control is a menu  and is part of the Master page. It is placed there because this needs to be available in all the pages. My user controls raises a even on item clicked. Now, My question is that Is there any way to know that the event has occurred in page_load of the current page in which I am in?



Categories: 
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