How to replace value of name for Hyperlink control during runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orked
    New Member
    • Jan 2009
    • 49

    How to replace value of name for Hyperlink control during runtime

    Hello,
    i want to change name of hyper link during runtime ,i put text box i take value from text box and put it as name of hyper link but when i reload page the original name of hyper link back again what i can i do to save the new value for ever.

    Thanks
    Orked.
  • Louis Dupont

    #2
    Check EnableViewState =true for your Control. Try as follow when press first button and then second button, Hiperlink Text will remain: "Your Link";
    (asp.net markup code)
    Code:
    <asp:HyperLink ID="HyperLink1" Text="My Link"
      runat="server" EnableViewState="true">
    </asp:HyperLink>
    <asp:Button ID="Button1" runat="server" 
     Text="Button" onclick="Button1_Click"/>
    <asp:Button ID="Button2" runat="server" 
     Text="Button" />
    (c# server-side code)
    Code:
    protected void Button1_Click(object sender, EventArgs e)
    {
      HyperLink1.Text = "Your Link";
    }
    Last edited by Frinavale; Oct 4 '10, 04:14 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

    Comment

    • orked
      New Member
      • Jan 2009
      • 49

      #3
      i know this point but i mean i have 2 hyper link they do not have text for them because i want to give them this value during runtime i will write the value in textbox and i will press button1 to apply this value and i will use hyper link 2 to reload page if i write test word in textbox and press button1 the text for hyper link 1 will be "test" if i press hyper link after that the original value for hyper link1 will back again but i want to save this value for ever and change it when i want
      This is my code:
      C#
      Code:
      protected void Button1_Click(object sender, EventArgs e)
          {
              HyperLink1.Text = TextBox1.Text;
          }
      asp.net code
      Code:
       <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
              <br />
          <asp:HyperLink ID="HyperLink1" runat="server"  EnableViewState="true" NavigateUrl="~/Default2.aspx">[HyperLink1]</asp:HyperLink>
          <br />
          <asp:HyperLink ID="HyperLink2" runat="server"  EnableViewState="true" NavigateUrl="~/Default4.aspx">[HyperLink2]</asp:HyperLink>
          <br />
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      if u have any suggestion please tell me
      Thanks
      Orked

      Comment

      Working...