Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

ASP.NET LinkButton

  • 16-10-2003 7:09pm
    #1
    Closed Accounts Posts: 30


    This is either really easy, or impossible.

    I have a web page with an ASP.NET hyperlink button. However, the hyperlink button initially doesn't link to anything. I would like, that when the user clicks the link, the hper-reference is dynamically created and the appropriate action taken.

    An example to help crear things up (this is obviously not what i actaully want to do :-)

    Image i have a picture of the moon, and one of the sun. (moon.jpg, sun.jpg) and i have a link which points to nothing.
    <asp:LinkButton id="LinkButton1" runat="server">LinkButton</asp:LinkButton>
    

    When the user clicks the link, I would like to return one of the images depending on the time of day. Now I know i could generate the link at render time, but what if the user does not click on the link for serveral hours? the original picture will be incorrect!

    so...
    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    
    ' What do i type here?
    
    End Sub
    


Comments

  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    eh?

    Javascript?


  • Closed Accounts Posts: 30 Lu[ifer


    eh?

    could you be more specific?

    or are you guessing?

    also i should add that within the LinkButton_Click handler, in reality i need to do more complex processing than simply choosing one picture or the other.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Using ASP.Net that should be trivial. You don't even need a link button.

    Set up your form. Put a *normal* button on it.
    In the code-behind, write some C# or VB.Net for the click-event of the button which determines the current time, and assigns the image to wherever you want it to be.

    Ta=dah.

    To do the same with a link button is virtually identical.

    BTW, if its actual navigation you want to do - not displaying an image - but don't want to decide the target till the user clicks, then you simply need to have code in the click-event to determine the URL you wan to go to, and then do a Server.Transfer(url); call to go there.

    jc


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Have the link call a javascript function, which has an array of hyperlinks, then do a redirect.

    This is done on the client side, so less work for your webserver
    eh?


  • Closed Accounts Posts: 30 Lu[ifer


    bonkey,

    that Server.Transfer("path") function is almost what i'm looking for.
    however, can that be used to return an x-octetstream MIME type,
    as in a file. E.g. is it possible to create a button, so that when
    the user clicks it, some server side processing is done and finally
    the user receives a download dialog box asking them to download
    a file? Something along the lines of what happens on sites like
    download.com possibly.

    When i try and do a Server.Transfer("moon.jpg") i'm getting the
    following
    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: Error executing child request for moon.jpg.
    


  • Advertisement
  • Closed Accounts Posts: 30 Lu[ifer


    Actually Response.Redirect("url") seems to do everything i need to,
    so unless anyone has any further advice, i guess this problem is
    solved. Thanks both typedef and bonkey.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Lu[ifer

    however, can that be used to return an x-octetstream MIME type,
    as in a file. E.g. is it possible to create a button, so that when
    the user clicks it, some server side processing is done and finally
    the user receives a download dialog box asking them to download
    a file? Something along the lines of what happens on sites like
    download.com possibly.

    Yes, it can. It, or any of the other redirection methods, should be able to handle that.

    I assume you have your files stored as actual files in the web-folder?

    One last thing to do is read the following :

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;312629

    Stupid MS - throwing Exceptions as part of "normal" usage of a command.

    jc


Advertisement