popup window according to CheckBox checked - c#

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.

Related

Control default action in ASP on Enter

This may be an easy question for you guys.
I have a web form with several buttons and only one textbox. When I enter a value in the textbox and press enter the method gets executed that is wired to the first top left button. I need to control what button's method gets executed (in this case it is a button in a whole different location that does db query).
I tried to alter tab index to have my desired button the lowest and I tried to pass focus to my desired button on page_load (like I would have done in Win Forms) but still if I enter text in textbox and hit eneter, the top left button's method gets executed.
I could put conditions in execution of top left button's method but that would be a workaround not a solution. So how do I control that behavior?
ASP.NET form has a defaultbutton property that specifies which button is clicked when ENTER is pressed. Just specify your button ID there. E.g.
<form id="form1" runat="server" defaultbutton="MyDbQueryButton">

pressing Enter on Dropdownlist causing postback

My application(asp.net) has few dropdowns which are dynamically created and all of them were AutoPostBack="false". if I select Item from dropdown and press enter it makes auto postback in the application. I tried to handle this issue OnKeydown event , but No Use.
Could some one help on the same .
Thanks
Pavan
Pressing submit button triggers the first button(forms default button) on the page.
Set UseSubmitBehavior="False" on your Buttons. This disables the "AutoPostback" on Enter.This prevents Postbacks on Enter completely.
Setting AutoPostBack="false" on a drop down list means it won't post back when you change the selection, the first button in an ASP.NET form is usually the default option so by pressing return you are probably invoking your forms submit button.
To avoid the postback when pressing enter inside a dropdown list it shuld be enough to add
<asp:DropDownList ...... onkeydown="return (event.keyCode!=13)"/>
But you will have se same problem if a user presses the enter key inside every control of the page. to disable the enter key on the entire page this is the code
<body onkeydown = "return (event.keyCode!=13)">
Can you please provide us with your code ? It would be easier to know which control is causing the postback by looking at your code.
My best guess is that you might have an asp.net button having the property "UseSubmitBehavior" set to true so when you are pressing enter the button is what is causing the postback.
To investigate further you can add this line of code to your Page_Load event to detect which control is causing the postback
if(IsPostback){
var controlName = page.Request.Params["__EVENTTARGET"];
}
Please let me know should you need any further clarification. :)

How to handle JavaScript's confirm dialog box on GridView's PageIndexChanging event?

What I'm trying to do is when the user tries to go to a different page inside a GridView control, I want to display JavaScript's confirm dialog box. If the user clicks on OK then the page should change. If not the page should not.
What I've done at the moment is display the confirm dialog box when the GridView 's PageIndexChanging event is fired, but I can't seem to find a way to check which button was clicked on in the confirm dialog box and how to handle it.
Also, the GridView is inside an UpdatePanel and the ScriptManager.RegisterStartupScript method is being used to display the confirm dialog box.
First, you need to register your script in the scriptmanager's DataItem list. Then create the client side scripting that handles this event.
You can also do so via the following method: ScriptManager.RegisterClientScriptBlock. Here is its documentation.
You can refer to some samples.

Avoid modal popup window closing on postback

How to avoid modal popup closing on postback ?.. I have a popup window displaying a grid view after a buttonclick event. but the pop up closes after the button is clicked ?? Can anyone help ??
Look at this question it may help you, just recall the modalpop.show() again.
How do I prevent the closing of modal popup window(ModalPopupExtender) on postback?
In general, you will need to preserve the modal popup state in order to reinitiate it again after the postback.
What I can suggest is to setup a hiddenfield control that only holds the state of your modal (0-1, true-false, whatever you like), and with Javascript, it's easy to change the hiddenfield value in order to reflect the current popup state.
When the page get posted back and reloads again, setup an onload javascript function that checks for the hiddenfield's value, and then react based on it to show the popup again as soon as the page is loaded.
You can use an asynchronous postback or set a flag and show the dialog again after the postback.

Postback on a submit button

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.

Categories

Resources