Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set url of an image using POST within code behind in ASPX page
    primarykey
    data
    text
    <pre><code>private void DisplayImages(string imageFile) { Image pImage = new Image(); pImage.ImageUrl = imageFile; this.Controls.Add(pImage); } </code></pre> <p>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?</p> <p>Please suggest.</p> <p>Update 1: I had forgot to add "this.Controls.Add(pImage);". I have added above.</p> <p>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.</p> <p>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.</p> <p><strong>Update 3</strong>: Below is the Javascript in the ASPX page.</p> <pre><code> &lt;script type="text/javascript"&gt; // 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("[?&amp;]([^=]*)=([^&amp;]*)", "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) == "&amp;" ) { matchID = matchID.substr(1); } if ( params[match[1]] != null &amp;&amp; !(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 &amp;&amp; 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&lt;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"; } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload