How to change the PostBackURL on an ImageButton - programmatically


Author
Message
Howard Bennett
Howard Bennett
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 496


Hello!



I'm wanting to change the PostBackURL on an image button based on the value in a text box. Here's my code:



protected void ImageButton2_Click(object sender, ImageClickEventArgs e)

{

if (this.txtCustomerCode.Text == "8868")



{

this.ImageButton1.PostBackUrl = "~/New Referral.aspx";

}



else



{

this.ImageButton1.PostBackUrl = "";

}

}



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?



Thanks - HB
Dustin Taylor
Dustin Taylor
StrataFrame Team Member (652 reputation)
Group: StrataFrame Users
Posts: 364, Visits: 771
Howdy BigGrin

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.

You could try checking the value of the text box in the post back and redirecting based on the value of the text box:

protected void Page_Load(object sender, EventArgs e)
{
   if(this.Page.IsPostBack && this.txtCustomerCode.Text == "8868"){
      this.Page.Response.Redirect("~/New Referral.aspx");
   }
}

Grabbing it before the postback is possible, but would mean venturing into the wide world of javascript and ajax Wink

Howard Bennett
Howard Bennett
StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)StrataFrame Novice (65 reputation)
Group: Forum Members
Posts: 57, Visits: 496
Thanks - that works - except I have other buttons that need to go to other pages regardless of what's in the txtCustomerCode.text.



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.



It's so "fun" learning new stuff! Crazy



HB



Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Create a private method on your form that accepts the object from the Load on a post back that determines which avenue to take.  There are other ways as well, but that would be a quick and easy way to get it going.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search