CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 1999
    Location
    India, TamilNadu, Chennai.
    Posts
    269

    Create LinkButton at run time in VB.Net->ASP.Net webapplication

    Hi,

    I want to create hyperlink button at run time in Vb.Net->asp.net web application. eg. mywebapp.aspx.vb (VB coding)


    I want to create hyperlink button through by vb coding, not by asp code.

    Thanks a lot,
    K.Babu
    Please avoid sending emails to my personal mail:
    write your doubts as thread in Codeguru
    Crystal Reports Forum
    .

    This will help all people having similar matters, and will let people who know solutions on the specific topic
    share their knowledge.

    Visit my company web site (Qmax Test Equipments Private Limited)

    Yours friendly,
    K.Babu

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    Code:
    Private sub DoSomething()
            '
            'Create control
            '
            Dim lbDemo As New LinkButton
            '
            'Modify properties
            '
            lbDemo.Text = "Click me!"
            lbDemo.Visible = True
            '
            'Add a handler for the click event
            '
            AddHandler lbDemo.Click, AddressOf LinkButton_Clicked
            '
            'Add the new control to the page, panel, placeholder, whatever...
            '
            Page.Controls.Add(lbDemo)
    End Sub
    
        Private Sub LinkButton_Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
            '
            'Gets called when our custom linkbutton is clicked
            '
        End Sub
    FYI: A LinkButton must be inside of a Form where Runat=Server.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Aug 1999
    Location
    India, TamilNadu, Chennai.
    Posts
    269

    error returned.

    Hi,

    i already tryied this method but its return the following error.


    Code:
    Server Error in '/CI' Application.
    --------------------------------------------------------------------------------
    
    Control '_ctl0' of type 'LinkButton' must be placed inside a form tag with runat=server. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.Web.HttpException: Control '_ctl0' of type 'LinkButton' must be placed inside a form tag with runat=server.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    
    [HttpException (0x80004005): Control '_ctl0' of type 'LinkButton' must be placed inside a form tag with runat=server.]
       System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
       System.Web.UI.WebControls.LinkButton.AddAttributesToRender(HtmlTextWriter writer)
       System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer)
       System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       System.Web.UI.Control.Render(HtmlTextWriter writer)
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       System.Web.UI.Page.ProcessRequestMain()
    
     
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573


    Quote Originally Posted by Craig Gemmill
    Code:
    Private sub DoSomething()
            '
            'Create control
            '
            Dim lbDemo As New LinkButton
            '
            'Modify properties
            '
            lbDemo.Text = "Click me!"
            lbDemo.Visible = True
            '
            'Add a handler for the click event
            '
            AddHandler lbDemo.Click, AddressOf LinkButton_Clicked
            '
            'Add the new control to the page, panel, placeholder, whatever...
            '
            Page.Controls.Add(lbDemo)
    End Sub
    
        Private Sub LinkButton_Clicked(ByVal sender As Object, ByVal e As System.EventArgs)
            '
            'Gets called when our custom linkbutton is clicked
            '
        End Sub
    FYI: A LinkButton must be inside of a Form where Runat=Server.
    Please avoid sending emails to my personal mail:
    write your doubts as thread in Codeguru
    Crystal Reports Forum
    .

    This will help all people having similar matters, and will let people who know solutions on the specific topic
    share their knowledge.

    Visit my company web site (Qmax Test Equipments Private Limited)

    Yours friendly,
    K.Babu

  4. #4
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892
    Yes... again, it has to be inside of a FORM where RUNAT=SERVER.

    I've attached an example that shows one method to place a control in the middle of a FORM.
    Attached Files Attached Files
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured