Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Re: How can you dynamically set the properties of a web server control?


Message #1 by rich@r... on Wed, 24 Jul 2002 02:59:17
Jon, I am new to asp.net programming and I also tried the same original 
method you described to try and dynamically pass a variable to a control. 
Could you explain how you resolved this. 
Elissa replied with the following tip:
hlDisplayItemText.NavigateUrl = "theUrlofpageIwant";
which doesn't make sense to me. If I set this within the control how does 
this solve the initial pass. Thanks for your help in advance. Rich



Hi,
> 
> I am trying to set one of the properties of a web server control 
> dynamically, and don't know how it should best be done.
> 
> Specifically, I want to dynamically set the NavigateURL property of this 
> Hyperlink control:
> 
> <asp:HyperLink runat="server" id="hlDisplayItemText" 
> NavigateUrl="DisplayItemText.aspx" Text="Display ItemText" 
> Target="_self" /> 
> 
> Firstly, this link should not always take the user to page 
> DisplayItemText.aspx - I want to be able to link to other pages, 
depending 
> on what else is going on on the page.
> 
> Secondly, I also want to pass variables from the current page to the 
> linked page (whether this linked page is DisplayItemText.aspx or some 
> other one), and was trying to do this via the query string.  However, my 
> first naive attempt (below) just threw errors:
> 
> Dim strPassVariable as String = "?Variable=xyz"
> 
> <asp:HyperLink runat="server" id="hlDisplayItemText" NavigateUrl=<% 
> Response.Write("DisplayItemText.aspx" & strPassVariable) %> 
Text="Display 
> ItemText" Target="_self" /> 
> 
> I suspect I am still thinking ASP 3.0 - there must be some super, slick 
> ASP.NET way of doing this!  Can anyone tell me how?
> 
> Thanks,
> 
> JON
Message #2 by planeswalk@h... on Wed, 24 Jul 2002 13:21:08
Hi, all!

Jon, you could check out the code I have below. It's pretty basic but the 
thing here is that you can pass off any href value to your asp:hyperlink 
control. Hope this helps!

-------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script runat="server">

  Sub submit_link(sender As Object, e As EventArgs)
    Dim linkValue As String
    If Page.IsPostBack Then
      linkValue = Request.Params("linkparam")
      sample1.NavigateUrl = linkValue
     End If
  End Sub

  Sub Page_Load(sender As Object, e As EventArgs)
    If Not Page.IsPostBack Then
      sample1.NavigateUrl=""
    End If
  End Sub

</script>

<form runat="server">
  <asp:textbox id="linkparam" 
               TextMode="SingleLine" 
               width="100" runat="server" />
  <asp:button id="linkbtn" 
              onClick="submit_link" 
              Text="click here" runat="server" /> <br />
  <asp:hyperlink id="sample1" 
                 Text="This is your life!" 
                 NavigateUrl="" runat="server" /> 
</form>

---------------------------

Cheers!

Marlon
Message #3 by "Richard Krol" <rich@r...> on Wed, 24 Jul 2002 13:38:48 -0400
Thanks for your help.


-----Original Message-----
From: planeswalk@h... [mailto:planeswalk@h...]
Sent: Wednesday, July 24, 2002 1:21 PM
To: aspx_beginners
Subject: [aspx_beginners] Re: How can you dynamically set the properties
of a web server control?


Hi, all!

Jon, you could check out the code I have below. It's pretty basic but the
thing here is that you can pass off any href value to your asp:hyperlink
control. Hope this helps!

-------------------------------
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script runat="server">

  Sub submit_link(sender As Object, e As EventArgs)
    Dim linkValue As String
    If Page.IsPostBack Then
      linkValue = Request.Params("linkparam")
      sample1.NavigateUrl = linkValue
     End If
  End Sub

  Sub Page_Load(sender As Object, e As EventArgs)
    If Not Page.IsPostBack Then
      sample1.NavigateUrl=""
    End If
  End Sub

</script>

<form runat="server">
  <asp:textbox id="linkparam"
               TextMode="SingleLine"
               width="100" runat="server" />
  <asp:button id="linkbtn"
              onClick="submit_link"
              Text="click here" runat="server" /> <br />
  <asp:hyperlink id="sample1"
                 Text="This is your life!"
                 NavigateUrl="" runat="server" />
</form>

---------------------------

Cheers!

Marlon


  Return to Index