1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Edit Sitefinity Pages in Visual Studio

Edit Sitefinity Pages in Visual Studio

13 posts, 0 answered
  1. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    24 Feb 2010
    Link to this post
    Hi.
    I am testing Sitefinity for future implementation.
    I have a WebSIte written in Visual studio, that I would like to integrate with Sitefinity.
    My idea of integration is to create similar structure of pages in Sitefinity, and add my code to them (by editing each of them) and additionally to add extra code (C# from App_code directory, external dll-s to references, etc).
    My question is:
    How can I edit each page (in visual studio) created by Sitefinity adding my own code (to aspx and cs files),
    How can I add C# files and dll-s to Sitefinity solution, so that I can see all parts in Sitefinity and to be able to modify whole website in Sitefinity.
    Greetings:
    Pawel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hello Pawel,

    How can I edit each page (in visual studio) created by Sitefinity adding my own code (to aspx and cs files)


    Sitefinity's pages are not physical files and you can add your logic using custom and user controls. Sitefinity supports external pages which could be standard ASP.NET pages, so you can add these pages to CMS SiteMap. Note that external pages cannot be managed through Page Editor - you are not able to drag-drop controls on the pages using Sitefinity. You have to manage them using Visual Studio.

    How can I add C# files and dll-s to Sitefinity solution, so that I can see all parts in Sitefinity and to be able to modify whole website in Sitefinity


    Sitefinity follows the structure of standard ASP.NET website. You can add your custom logic to the solution and then use it in other classes or controls. If you have already created custom control you can register them in the web.config, <toolboxControls> section

    <toolboxControls>   
     <clear />
             <!--register user control-->
            <add name="Splitter" section="Custom" url="~/CustomControls/SplitterControl.ascx" />
             <!--register custom control from Telerik.Samples.dll-->
            <add name="CustomControl" section="Custom" type="Telerik.Samples.WebControls.CustomControl, Telerik.Samples"/>
     
                ....
                     ....


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    24 Feb 2010
    Link to this post
    Hi.
    Thanks for your answer.
    What can happen if current pages logic contains redirection to other pages?
    If I convert them to custom controls (ascx) and add them to a page in Sitefinity, what address should I put in redirection method, if webpages in Sitefinity are generated on runtime?
    e.g. I have Response.Redirect("./UpdateClientData.aspx"); in my application
    what address should I put if I create similar page in sitefinity engine?

    And another question - how can I reuse my security provider, to have the same authentication and authorization mechanism?

    Greetings:
    Pawel

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hi Pawel,

    Response.Redirect works in Sitefinity in the same way as in each other ASP.NET website. You can use each ASP.NET Role, Membership and Profile providers. Note that the backend supports only one membership provider.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    24 Feb 2010
    Link to this post

    Hi.
    Thanks for your answers.
    This clarifies a lot, but there are other problems, I don't know how to solve in such approach with controls.
    In some o my webpages currently I have:
     

     

    protected

     

    override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)

     


    that is fired to identify/filter some grids on the web page:
     

    if

     

    (sourceControl.GetType() == typeof(RadGrid))

     

    {

     

    RadGrid grid = (RadGrid)sourceControl;

     

     

    if (grid.ID == "RadGrid1")

     

    ....................

    and perform some operations.
    I use it to catch ajaxRequest() and  ajaxRequestWithTarget() server side.
    How can I do the same on user control (I mean identify source Telerik "subcontrol" such as RadGrid - as a part of my UserControl)?
    Implementing IPostBackEventHandler does not solve the problem as its method

    public

     

    void RaisePostBackEvent(string eventArgument)

     

     takes only one, text parameter and does not allow to identify a grid, that sends an event.
    Greetings:
    Pawel
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Feb 2010
    Link to this post
    Hi Pawel,

    You could try using __doPostback with event handler on the client event for the control that should make the post back.

    __doPostBack("<%= RadGrid1.UniqueID %>", "RowClicked:" + this.Rows[index].ItemIndex);


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    24 Feb 2010
    Link to this post
    Hi.
    I haven't catched. Could you give me a server side example of handling such event?
    Greetings:
    Pawel
  8. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    25 Feb 2010
    Link to this post
    Hi.
    I noticed that, using __doPostBack() and passing a detailed control (e.g. RadGrid) UniqueID does not cause RaisePostbackEvent(string eventArgs) on UserControl control side. It happens only when I put my UserControl UniqueID. This does not solve my problem as I can't intercept e.g. a RadGrid, that is causing a postback.
    If a page has static and known number of grids I can Identify them by name, included in eventArgs (on __doPostbackSide by concatenation) - this is in fact not a nice solution.
    But if I have to identify one of dynamicly (programatically) generated grids, or gain other object type, that causes a postback, it does not solve the problem.
    Is it a way to intercept an internal control object, that sends AJAX request to a server using UserControl?
    Greetings:
    Pawel
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Feb 2010
    Link to this post
    Hello Pawel,

    1. __doPosback works perfectly when you pass the RadGrid instance unique ID.
    2. You can subscribe for ItemCommand of the dynamically generated RadGrid control. The ItemCommand occurred when you a button is clicked in RadGrid control. Then you can get the id from the ItemCommand source and save it or pass it somewhere else.

    void rg_ItemCommand(object source, GridCommandEventArgs e)
      {
            // use   var sourceID = (source as RadGrid).ID;
          var ControlID = ((Telerik.Web.UI.RadCompositeDataBoundControl)(source)).ID;       
     
      }

    3. You can use Request.Params.Get("__EVENTTARGET");

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    25 Feb 2010
    Link to this post
    Hi.
    Thanks for your answer.
    I think this is not what I can use.
    I will write more about my scenario.
    I have now two grids on page (and it is possible that I will have more, even dynamic grids on other pages in the future).
    For each grid, there is a button (HTML not ASP.net) that has a call of a JavaScript function. For RadGrid1 there is first function (that does something and finally calls ajaxRequestWithTarget(ajaxRequestWithTarget('<%= RadGrid1.UniqueID %>', '...........' );). For RadGrid2 there is a second function (that does something and finally calls ajaxRequestWithTarget(ajaxRequestWithTarget('<%= RadGrid2.UniqueID %>', '...........' );).
    As I mentioned I can have many dynamic grids in the future and dynamic HTML buttons, generated programatically (I write it, because I consider to bring my scenario into Sitefinity and want to be sure, that even if I change my current page with known, static RadGrids, to dynamic ones, I will be able to develop my solution based on UserControls and dynamic/programmatic grids generation, loaded later on to sitefinity).
    As you can see, there is not exactly a click on any position/row of a grid (row on a grid 1 and 2 is only marked before buttons click), but rather an Ajax request send by HTML button. I think it means that ItemCommand will not be fired when I click button and call ajaxRequestWithTarget or __doPostBack (point 2. of your answer).

    According to point 1. - __doPostBack send by RadGrid as a part of UserControl causes of course postback, but does not fire RaisePostBackEvent(string eventArgs) of UserControl Itself. It is fired only when I put UserControl.UniqueId to __doPostBack. Maybe I am doing something wrong, but according to many other information from internet forums, it is correct behavior (user control RaisePostBackEvent is fired when the postback on this control is fired, not on other control included in this user control).

    According to point 3. - Yes I can take Request.Params.Get("__EVENTTARGET"); to gain a control name, but only in Page_load, because there is then no server side event handler that handles my buttons clicks, that sends postbacks on behalf of grids. If I am wrong, and there is such event, It can solve my problem.

    I need a solution that allows me to send a request/postback on behalf of a control (RadGrid or other included in UserControl), and allow me to catch/intercept such request as an event (page load does not meet this criteria - I need indentification of the event, not an execution every time a page is loaded). Additionally I use Ajax in such approach so if I send something on behalf of e.g. RadGrid1 and I have configured my AjaxManager, all dependent controls will be refreshed. The question is, whether it can be implemented similarly using UserControl Instead of Page and then loaded to Sitefinity.

    Greetings:
    Pawel




  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Feb 2010
    Link to this post
    Hello Pawel,

    1. You do not have to inherits from IPostBackEventHanlder in your control.
    2. The ItemCommnad works properly. I tested this with two dynamically generated RadGrid controls with dynamic buttons. The Page_Load is not the proper place where you should subscribe for the events due the RadGrid lifecycleand Page lifecycle. You have to create the control OnInit and there subscribe for ItemCommand.  The ItemCommand event is raised when a button is clicked in the Telerik RadGrid control. This allows you to provide an event-handling method that performs a custom routine whenever this event occurs.Buttons within a Telerik RadGrid control can also invoke some of the built-in functionality of the control. Fires if any control inside Telerik RadGrid rises a bubble event. This can be a command button (like Edit, Update button, Expand/Collapse of an items) The command arguemtn carries a reference to the item which rised the event, the command name and argument object. A GridCommandEventArgs object is passed to the event-handling method, which allows you to determine the command name and command argument of the button clicked.

    Also you can work with GridButtonColumn instead of using HTML controls.

    Take a look at this article that explains Postback from ajaxified grid.

    If nothing of this helps to you, you can create external pages in Sitefinity.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  12. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    25 Feb 2010
    Link to this post
    Hi.
    I thing there is a small misunderstanding.
    I don't want to make postback for particular row, so putting a button per each row, and handling ItemCommand is not a solution.
    I have one external button (html button) per each grid (I can mark many rows in grid). Then I gather marked grid rows identifiers in javascript, and sent it as a concatenated string by ajaxRequestWithTarget('<%= RadGrid1.UniqueID %>', concatenatedString ) to a server (so I send a request on behalf of whole grid, not on behalf of a row). I do it to handle marking rows while using paging, to leave marked rows even after grid page change.
    On server side I catch such event by ovverriding Page's RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument) in which I identify a particular grid object.
    When I convert my Page to a UserControl type, I have to remove:

    protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)

    as a UserControl class does not have in its inheritance hierarchy a class that posses such method signature.
    So now I do not have a method to catch a click on behalf of the grid.
    If I put __doPostBack('<%= RadGrid1.UniqueID %>', concatenatedString), which UserControl handler method allows me to intercept this postback?
    I tried to implement IPostbackEventHandler for my UserControl but, it handles only a requests, when __doPostBack('<%= UserControl1.UniqueID %>', concatenatedString) is passed (so only when my UserControl id is passed).
    So the question is - is it possible to catch such request server side in UserControl, and additionally make an effect as particular grid caused such request (this is for AjaxManager to update objects dependent on the grid that passed request/event)?

    I would like to avoid using external pages, because there is a problem with graphics integration with Sitefinity. Using controls is much easier so I would appreciate further discussion to solve such problem.

    Greetings:
    Pawel
  13. Pawel
    Pawel avatar
    12 posts
    Registered:
    02 Jan 2008
    26 Feb 2010
    Link to this post
    Hi.
    Thanks to your advices I solved the problem.
    Maybe a short description will help someone in similar situation.
    To identify an internal grid request from UserControl, as there were no event that intercepted it for whole grid (not a row), I put ajaxRequestWithTarget('<%= RadGrid1.UniqueID %>', eventArg) on JavaScript, and added grid's identifier to eventArg. Then in Page_Load I intercept an eventArg by Request.Params.Get("__EVENTARGUMENT"); and check, whether it contains the identifier of the grid. If so I execute the same body of method as I had previously in RaisePostBackEvent, when I had all code on Page (not on UserControl).
    This allows me to intercept a grid request and keep AJAX refresh (because I have RadGrid1 -> RadGrid1 refreshment dependency in AjaxManager configured).
    It works fine, and allows to work a UserCOntrol with internal grids (but can be applied for any control) like a Page with postback and AJAX partial update.
    Again, thanks for your support.
    Greetings:
    Pawel
Register for webinar
13 posts, 0 answered