how to create multiple hyperlinks dynamically?
-
I have button which opens the dialog box to select a filename. the filename with path i am storing in textbox. when i click on the button , i want to create one hyperlink and set its text and navigateurl property to textbox1.text. i can able to create one hyperlink. but i want to create as many hyperlinks as button clicked by the user and textbox is not blank. my code on button click event is Dim HyperLink As HyperLink = Nothing HyperLink = New HyperLink() HyperLink.ID = "HyperLink" & i HyperLink.Text = TextBox1.Text HyperLink.NavigateUrl = "file:///" & TextBox1.Text PlaceHolder1.Controls.Add(HyperLink) PlaceHolder1.Controls.Add(New LiteralControl("
")) This is working for one hyperlink , when i click on 2nd time button , the text changes to textbox1.text but it deletes the 1st hyperlink. i tried Me.Controls.Add(New LiteralControl("<a href = " + HyperLink.NavigateUrl + ">" + TextBox1.Text + "</a>")) but its not working. Please help me as i am stuck here since one week. i dont know how to get rid of this problem. i tried with ajaxextension, but i dont know how to use it. one more thing i dont want to upload , i just want to attach this file to email. and if user wants to see this file he can click on hyperlink and he/she can open from the page and they can see the list of files that they have selected for the attachment. Please help...with the code. Thanks in advance. Hemrk. -
I have button which opens the dialog box to select a filename. the filename with path i am storing in textbox. when i click on the button , i want to create one hyperlink and set its text and navigateurl property to textbox1.text. i can able to create one hyperlink. but i want to create as many hyperlinks as button clicked by the user and textbox is not blank. my code on button click event is Dim HyperLink As HyperLink = Nothing HyperLink = New HyperLink() HyperLink.ID = "HyperLink" & i HyperLink.Text = TextBox1.Text HyperLink.NavigateUrl = "file:///" & TextBox1.Text PlaceHolder1.Controls.Add(HyperLink) PlaceHolder1.Controls.Add(New LiteralControl("
")) This is working for one hyperlink , when i click on 2nd time button , the text changes to textbox1.text but it deletes the 1st hyperlink. i tried Me.Controls.Add(New LiteralControl("<a href = " + HyperLink.NavigateUrl + ">" + TextBox1.Text + "</a>")) but its not working. Please help me as i am stuck here since one week. i dont know how to get rid of this problem. i tried with ajaxextension, but i dont know how to use it. one more thing i dont want to upload , i just want to attach this file to email. and if user wants to see this file he can click on hyperlink and he/she can open from the page and they can see the list of files that they have selected for the attachment. Please help...with the code. Thanks in advance. Hemrk.Does it post back to create the hyperlink ? THe postback is losing the dynamically created control because, well, it doesn't get recreated during te postback. You need to store the details of all the controls you created in viewstate so that on postback you recreate them all. Actually, you can just create links with javascript, if you know the URLs, from the textbox. No postback or AJAX needed.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
I have button which opens the dialog box to select a filename. the filename with path i am storing in textbox. when i click on the button , i want to create one hyperlink and set its text and navigateurl property to textbox1.text. i can able to create one hyperlink. but i want to create as many hyperlinks as button clicked by the user and textbox is not blank. my code on button click event is Dim HyperLink As HyperLink = Nothing HyperLink = New HyperLink() HyperLink.ID = "HyperLink" & i HyperLink.Text = TextBox1.Text HyperLink.NavigateUrl = "file:///" & TextBox1.Text PlaceHolder1.Controls.Add(HyperLink) PlaceHolder1.Controls.Add(New LiteralControl("
")) This is working for one hyperlink , when i click on 2nd time button , the text changes to textbox1.text but it deletes the 1st hyperlink. i tried Me.Controls.Add(New LiteralControl("<a href = " + HyperLink.NavigateUrl + ">" + TextBox1.Text + "</a>")) but its not working. Please help me as i am stuck here since one week. i dont know how to get rid of this problem. i tried with ajaxextension, but i dont know how to use it. one more thing i dont want to upload , i just want to attach this file to email. and if user wants to see this file he can click on hyperlink and he/she can open from the page and they can see the list of files that they have selected for the attachment. Please help...with the code. Thanks in advance. Hemrk.