﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WebForms (How do I?)  » How to change the PostBackURL on an ImageButton - programmatically</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sun, 05 Apr 2026 15:52:01 GMT</lastBuildDate><ttl>20</ttl><item><title>How to change the PostBackURL on an ImageButton - programmatically</title><link>http://forum.strataframe.net/FindPost17325.aspx</link><description>&lt;br&gt;
Hello!&lt;br&gt;
&lt;br&gt;
I'm wanting to change the PostBackURL on an image button based on the value in a text box.  Here's my code:&lt;br&gt;
&lt;br&gt;
        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)&lt;br&gt;
        {&lt;br&gt;
            if (this.txtCustomerCode.Text == "8868")&lt;br&gt;
&lt;br&gt;
            {&lt;br&gt;
                this.ImageButton1.PostBackUrl = "~/New Referral.aspx";&lt;br&gt;
            }&lt;br&gt;
&lt;br&gt;
            else &lt;br&gt;
&lt;br&gt;
            {&lt;br&gt;
                this.ImageButton1.PostBackUrl = "";&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
&lt;br&gt;
Right now - the button doesn't do anything...which is what I want if the Customer Code is incorrect.  However - when the code is correct - it still does nothing.  Can someone point me in the right direction here?&lt;br&gt;
&lt;br&gt;
Thanks - HB</description><pubDate>Wed, 25 Jun 2008 16:06:33 GMT</pubDate><dc:creator>Howard Bennett</dc:creator></item><item><title>RE: How to change the PostBackURL on an ImageButton - programmatically</title><link>http://forum.strataframe.net/FindPost17348.aspx</link><description>Create a private method on your form that accepts the object from the Load on a post back that determines which avenue to take.&amp;nbsp; There are other ways as well, but that would be a quick and easy way to get it going.</description><pubDate>Wed, 25 Jun 2008 16:06:33 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: How to change the PostBackURL on an ImageButton - programmatically</title><link>http://forum.strataframe.net/FindPost17338.aspx</link><description>Thanks - that works - except I have other buttons that need to go to other pages regardless of what's in the txtCustomerCode.text.&lt;br&gt;
&lt;br&gt;
I may have to pass the text to the target page and have it check what's passed by this page before loading...don't know how to do that either...but hopefully there's a way.&lt;br&gt;
&lt;br&gt;
It's so "fun" learning new stuff! :crazy:&lt;br&gt;
&lt;br&gt;
HB&lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 25 Jun 2008 12:44:56 GMT</pubDate><dc:creator>Howard Bennett</dc:creator></item><item><title>RE: How to change the PostBackURL on an ImageButton - programmatically</title><link>http://forum.strataframe.net/FindPost17329.aspx</link><description>Howdy :D&lt;P&gt;My guess is that the value isn't getting set until after the initial postback. When you click the button, it has to make a postback in order for tha code in the click to be fired, so by the time you overwrite that postback URL, it has already happened. &lt;/P&gt;&lt;P&gt;You could try checking the value of the text box in the post back and redirecting based on the value of the text box:&lt;/P&gt;&lt;P&gt;[codesnippet]protected void Page_Load(object sender, EventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; if(this.Page.IsPostBack &amp;amp;&amp;amp; this.txtCustomerCode.Text == "8868"){&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Page.Response.Redirect("~/New Referral.aspx");&lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}[/codesnippet]&lt;/P&gt;&lt;P&gt;Grabbing it before the postback is possible, but would mean venturing into the wide world of javascript and ajax ;)</description><pubDate>Wed, 25 Jun 2008 11:29:03 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item></channel></rss>