Postback on a submit button - c#

I have a page that has 4 tables. Initially when the page is loaded, it shows 1 & 2. Thats working fine. On Post back(When Submit is clicked), it should show 3 & 4. Even thats working fine(code shown here). When the submit is clicked again, it has to call updatePaymentInfo() and redirect. Is there something to write as a condition to call UpdatepaymentInfo() because when submit is clicked, it is taking as an other postback and showing me 3 & 4 again.
protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
try
{
if (Page.IsPostBack)
{
trtest.Visible = false;
trCCandBilling.Visible = true;
trtest2.Visible = true;
}
else
{
UpdatePaymentInfo();
Response.Redirect(ApplicationData.URL_MERCHANT_ACCOUNT_HOME, true);
}
}
}

My thought on the easiest way to do this is to have two image submit buttons in the same place. Button A is the one you already have button B is a new one that whose submit handler runs UpdatepaymentInfo and redirects.
Button B starts off invisible while button A is visible. When Button A is clicked in addition to the visibility changes you hide button a and show button B. Then when they click button B the right stuff happens.
Its not that elegant though.
Another solution might be storing values in the page to indicate the current page state that you can then check on button click.

It sounds like you're having trouble managing the current state of your page. You could try:
Having a second submit button. It would be stylistically indistinguishable from the first, and would be hidden/shown accordingly, but would have its own click event.
Placing a hidden form value on the page to track the current "step" of the process.
Breaking the page into two pages, since from the user's perspective it's clearly a two-page process.
My personal favorite, move to MVC :) Though it's understandable if you're stuck in a pre-existing WebForms app and there's just no budget to re-write it.

I guess that imgbtnSubmit_Click handles Click event of the Submit button so this method will be called only during the postback so the condition is incorrect.
I would not use this approach. ASP.NET contains controls which support these requirements. Check MultiView and Wizard. Create separate view with table 1 & 2 and button and another view with table 3 & 4 and button. Button on the first view will switch the view and button on the second view will call the method and redirect.

Another possible way to do this is keep your current set up and add a command argument to the button. By default it has some argument that you check on the first click. Then checking the command argument on the first click you do your showing and change the command argument to be something different. So on the next button click you do the work associated with the second command argument. Thus flipping the work done without having to hide or show a new control.

Related

popup window according to CheckBox checked

If user don't checked, I want to show asp:ModalPopupExtender and get numeric value from this form.
I'm using asp.net wizard control. I don't know "finish" button id. Can somebody help me?
You should set the target of the ModalPopupExtender as a dummy control, i.e., a hidden Button, LinkButton,... that never is going to be clicked by the user.
The Wizard control have a method called FinishButtonClick. Here is where you have to check the state of the CheckBox and show or not the popup calling to the method Show() of the ModalPopupExtender. You also can call to the Click() method of the hidden control or do it with JavaScript usign the BehaviourID of the ModalPopupExtender. Your choice.
Cheers!
To get "Finish" button id, just open the page in browser & view the rendered html code (Right Click -> View Source). From their you can get the finish button id.
And after getting "Finish" button id, you can easily associate a Client-Side event to do the required job.

Asp.net 2 buttons return same page with different data

On my Ascx page ive got 2 buttons, those buttons redirect to same page atm. (because page should be exactly same). In Page_Load() method sender parameter doesnt have any parameters. How do i tell Page_Load event which button was clicked? so i can load different data depends on which button was clicked?
Are there any way to do it more dynamicly? or do i have to create a separate page for each button?
I dont know what you trying to do , this could be silly but still you can achieve this by doing something like this
Button1_Click
Response.Redirect("Default.aspx?id=1")
Button2_Click
Response.Redirect("Default.aspx?id=2")
Then on the load event
if(Request.QueryString["id"]==1)
button1
else
button2
You can also multiple parameters to a page like this
Response.Redirect("Default.aspx?id=1&name=xyz")
And retrieve it
Request.QueryString["name"]=="xyz"
The postback event for the button click is called right after the Page_Load, there you can tell which button was clicked and then do some stuff on the OnPreRender method
Or maybe I have misunderstood and you redirect to another page. In this case, I'm with Ashwini Verma, add some query string or pass some var through Session. The choice is yours

Load Multiple UpdatePanel Controls With JavaScript Button Clicks

I have 3 update panels on a page. Each of them is set to conditionally update. In each update panel I have a single button control that when clicked will populate the panel with data. Each panel is independent of one another.
Everything is working fine when you manually click each one of the 3 buttons in their respective panel. The issue I am having comes up when I use JavaScript to click the buttons. I have success when executing a single JavaScript call but when I try to click all 3 buttons with JavaScript, things behave sporadically. Depending on where I place the JavaScript calls in my code, different panels work and the others do not.
For example:
__doPostBack('btnBindTeamTicketList', '');
__doPostBack('btnBindPriorityList', '');
__doPostBack('btnSearchTemplate', '');
will show the panel that holds the 'btnSearchTemplate' button, but not the others. Different results occur when I change the sequence around.
Is there a way to click my 3 independent buttons (each in its respective panel) using JavaScript so that each panel will load as if I were clicking on them individually? I am guessing this has to do with the AJAX somehow conflicting with each other or a timing problem. Anyone point me in the right direction?
I am using ASP.NET 3.5/C#
I think you should do one postback. Put a hidden update panel in your page and put a button inside this new update panel. This button should call events
btnBindTeamTicketList_Click(null, null)
btnBindPriorityList_Click(null, null)
btnSearchTemplate_Click(null, null)
and should update the other update panels like upTeamTicketList.Update(). Now try clicking this new button.

submit button in ascx posts back, but does not enter the ascx_load

this is driving me NUTS!
i have a submit button in a header.ascx, which is in every page.
it's now a normal html submit button because i thought maybe the asp:button was giving me trouble, but as it turns out the troubles are still here.
so what happens: i click on the submit button (in the .ascx), the page reloads.... without entering the load event of the ascx.
click again... still not
then click 1 to 3 times again (random, sometimes i have to click 3 times total, sometimes 7): still not
then click again: tadaa! there is the load event breakpoint hitting....
there must be a simple reason, please tell me what it is.....
EDIT
there is some outputcaching going on ( defined in the page), posts are not cached, right??

disable default behaviour of Internet Explorer

I am using asp.net C#.
I have one html input field, and 3 image buttons (asp.net controls)
ImageButton 1 = perform delete operation
ImageButton 2 = perform Edit operation
ImageButoon 3 = perform duplicate operation
My problem occurs when the user presses the enter key when the input field is in focus.
When he presses the enter key the browser automatically fires by default the next button.
In my case it is the delete operation.
How can I prevent this?
Configure DefaultButton property properly.
you can also hide a button at the top of your page/form that will attract the attention of IE when you hit enter.
<button style='position:absolute;left:-1000px'>IE sux</button>
that button won't display on the screen but IE will click it whenever you hit enter. since it has no action on click, nothing will happen.
note: only works in IE9. perhaps useful with the default button option above.
As mentioned above, use the form's defaultbutton property or it you use a panel use that of the panel.
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton(VS.80).aspx

Categories

Resources