0

I have created a dynamic image using Generic Handler[.ashx] and then assigning the same to the Image on my user control from code behind.

string capt = //some random logic value.
imgCaptcha.ImageUrl = "~/BO/term.ashx?param=" + capt;

Now on some button event on same usercontrol, I want to read the query parameter of the ImageUrl

 protected void btnVerify_Click(object sender, EventArgs e)
 {
     //something like this
     string param = Request.QueryString["param"]

 }

But Request.QueryString wont give me anything as the usercontrol is added on some .aspx page so Request path will be the same .aspx page which do not have the query parameters.

But imgCaptcha.ImageUrl give me some path which is ~/BO/term.ashx?param=123456.

Now I want to read this information using some .Net standard class. Is there anything which will solve my query?

Note : I am not much interested in using string methods.

2 Answers 2

1

you can generate uri and retrieve query string parameters however string split is better:

 Uri uri = new System.Uri(Page.Request.Url, VirtualPathUtility.ToAbsolute(Image1.ImageUrl));
 var parameters = System.Web.HttpUtility.ParseQueryString(uri.Query);
 string value = parameters["param"];
Sign up to request clarification or add additional context in comments.

Comments

0

You can't do that. You you can read it only from the term.ashx. So you have to parse the ImageURL parameter or save the parameter value somewhere.

For example you can save it in the ViewState:

string capt = //some random logic value.
ViewState["imgCaptchaParameter"] = capt;
imgCaptcha.ImageUrl = "~/BO/term.ashx?param=" + capt;

And use it like this inside the method:

protected void btnVerify_Click(object sender, EventArgs e)
{
    //something like this
    string param = ViewState["imgCaptchaParameter"].ToString();
}

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.