By default the asp.net image control trys to be helpful and automatically encodes anything set to the ImageUrl property, so:
imgSomething.ImageUrl = "Generator.aspx?x=1&y=2&z=3";
Becomes
"Generator.aspx?x=1&y=2&z=3"
The problem is I want to pass Base64 encoded parameters, which I need to manually Server.UrlEncode because each one can contain charater that'll cause problems otherwise.
So basically my question is: How do I stop the Image control from automatically UrlEncoding what I set to the ImageUrl parameter?
I think you should use server control. not asp control.
<img ID="Image2" src="" alt="" runat="server" />
Me.Image2.Src = "&&&"
it works.
We ran into the same issue. Our workaround was to package all the parameters into one URLEncoded and Base64-encoded parameter, and split it ourselves on the other side. We notice a similar approach in WebResource.axd and ScriptResource.axd.
Quick and dirty way (using simple helper methods for Base64 encoding/decoding):
string parameters = args.Join('|');
imgSomething.ImageUrl = "Generator.aspx?d=" + Server.UrlEncode(Base64Encode(parameters));
in Generator.aspx:
string data = Base64Decode(Server.UrlDecode(Request.QueryString["d"].ToString().Trim()));
string[] parameters = data.Split('|');
If you want to use querystring-style parameter strings (i.e., x=1&y=2&z=3), there is a bunch of sample code out there that will let you move between a string and NameValueCollection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With