private void DisplayImages(string imageFile)
{
Image pImage = new Image();
pImage.ImageUrl = imageFile;
this.Controls.Add(pImage);
}
above is the current code but the image is not getting displayed and I want to check URL value. I have a javascript function that will check for URL and return the URL. All I need to do is assign the URL returned from javascript to the above image using what is called as POST. How can I achieve this in code-behind in above function?
Please suggest.
Update 1: I had forgot to add "this.Controls.Add(pImage);". I have added above.
Update 2: I am creating Image control (As shown in the code) during onLoad of the page. The URL for this is usually longer and comes from an XML. I printed the URL value before assigning to image control.
Now for some reason, image doesn't render in browser. Just now I found that even that URL when rendered in separate browser gives me HTTP 403. The person who built that URL and stored in XML tells me that I should use Javascript and do a POST by sending this URL. I need to know how I can do the javascript in the below code such that the image URL gets assigned after the POST method. Hope this clarifies.
Update 3: Below is the Javascript in the ASPX page.
<script type="text/javascript">
// Open URL in new window with a a post instead of the get
function posturl(url) {
alert("I am here");
var qsBegin = url.indexOf("?");
var qsPattern = new RegExp("[?&]([^=]*)=([^&]*)", "ig");
var match = qsPattern.exec(url);
var params = new Array();
while (match != null) {
// matched text: match[0]
// match start: match.index
// capturing group n: match[n]
var matchID = match[1];
if ( matchID.charAt(0) == "&" ) {
matchID = matchID.substr(1);
}
if ( params[match[1]] != null && !(params[match[1]] instanceof Array) ) {
var subArray = new Array();
subArray.push(params[match[1]]);
subArray.push(unescape(match[2]));
params[match[1]] = subArray;
} else if ( params[match[1]] != null && params[match[1]] instanceof Array ) {
params[match[1]].push(unescape(match[2]));
} else {
params[match[1]]=unescape(match[2]);
}
match = qsPattern.exec(url);
}
var myForm = document.createElement("form");
//myForm.setAttribute("target", "_blank");
myForm.method="post" ;
myForm.action = url.substring(0,qsBegin) ;
for (var k in params) {
var myInput;
// Check for params with the same name.
if ( params[k] instanceof Array ) {
for ( var i=0; i<params[k].length; i++ ) {
myInput = createFormInput(k, params[k][i]);
myForm.appendChild(myInput) ;
}
} else {
myInput = createFormInput(k, params[k]);
myForm.appendChild(myInput);
}
}
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
//return "did you get what you wanted";
}
</script>