0

I'm writing an ASP web application with VB back-end. What I'd like to do is generate a url and display this in control on the page. For example if I have a label and a button on the form. The label is blank. When the button is clicked the following code fires:

 Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGenerate.Click
    label1.Text = "Hello"
End Sub

What I'd like to have is a url that would point to my ASP Page with the words "Hello" in the label. Is this possible?

2 Answers 2

2

You could do the following:

{siteaddress}/aspxpage.aspx?label=hello

then in you aspx page do something like:

<asp:label runat="server" id="yourLabelId" text='<%=Request.QueryString("label")%>' />

Or in the Page_Load:

yourLabelId.Text = Request.QueryString("label")

I would recommend validating the data before just writing it into the page.

Sign up to request clarification or add additional context in comments.

1 Comment

If I use this. And I am not doing a POSTBACK, i.e. the individual is using the application as normal, will it still look for "label" in the query string?
1

Pass the text in query string e.g. suppose relative path of the page is /pagename.aspx , you can pass the query string as per given example below:

/pagename.aspx?text=hello

in c# write following code in Page_Load event

//You don't have to check the url all the time , so just check it if page is not posting back (first time after user visits the page and ignore all other same page post backs. Label can maintain its control state (text value) after every postback, so assign it only once to increase performance
if (!IsPostBack)
{
    //Check if query string is provided or not , if it is not provided take some default text, I am taking empty string as default text.
    string givenText = (Request.QueryString["text"] == null)?"":Request.QueryString["text"];
    label1.Text = givenText;
}

You can also create a property for text given through query string and default text.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.