Invoking button click event on one page from another page ASP.NET - asp.net

I have two aspx pages i.e. default1.aspx and default2.aspx. Default1 contains some controls, tables etc. I am showing Default2.aspx into anthor window using hyperlink, setting its target to _blank. What I need is to call a button event which is placed inside Default1.aspx as soon as Default2 is closed (i.e. as soon as the new window showing default2 is closed).
Although, I know that this can be accomplished by showing the default2 into a modal popup i.e. show the default2 into a modal dialog and after that call the button event using javascript. But due to some reasons i am not permitted to do that.
Could some one please show me how i could do that.

If I was you, I'd refactor what will the button in page 1 do in a helper method that both of pages can call.

Related

How to switch among tabs with the Ajax Control Toolkit TabContainer?

I have 3 ascx controls loaded in one aspx file as a tabbed manner. I have one button in first ascx control. If the button is clicked then I have to move to next tab. How to move to next tab?
I assume that you or your organization wrote the 3 ascx controls?
You're going to have to alert the parent of the tabbed control (the page?) that a child of the tabbed control (the ascx control) has requested that the tab control progress to another tab.
The simplest, least coupled way I know how to do this is with a custom event. The steps would be as follows:
Implement an event in your ascx control that is raised when the button in your ascx control is clicked. There's an example of this in this Q+A.
Since you're using Visual Basic, the syntax for the fourth step will be different. I describe this in the next step, below.
Set up a handler for that event in the page. (This is Step 4 in the example I linked to.)
The simplest way to associate the handler with the user control is in the markup:
<uc:MyUserControl TabChangeRequested="MyUserControl_TabChangeRequested"
runat="server" id="userControl1" />
This example assumes that MyUserControl_TabChangeRequested is a public or protected method of your page.
If this doesn't work, you can do the association programmatically. How you do this depends on whether the user control is visible to the page itself, or is a child of the tab control. If the user control is a child of the page, you can use this code (in Page_Load):
AddHandler userControl1.TabChangeRequested, AddressOf MyUserControl_TabChangeRequested
It's a very different syntax to that of C#, which can make examples confusing.
If the user control is a child of the tab control rather than being declared at the page control, you need to first get a reference to the user control from within the control collection of the specific tab:
Dim uc as MyUserControl = TabControl1.Tabs(0).FindControl("userControl1")
AddHandler uc.TabChangeRequested, AddressOf MyUserControl_TabChangeRequested
Depending on the tab control and how it was written, you might need to look in the tab control's own children rather than the tab's. The first line of the previous example would look like this:
Dim uc as MyUserControl = TabControl1.FindControl("userControl1")
In your handler, do whatever you need to do to change to the next tab.

How Does ASP.NET Knows Which Button Caused a PostBack?

I'm using ASP.NET 4 to create a page with elements that are used in a jQuery UI Sortable plugin.
All of these elements contain a button (implemented as a submit button) with the name SubmitButton. All but one of these buttons are hidden in the page's Load event. But if I drag the element to another position, and then submit the page using that button, ASP.NET gets confused.
ASP.NET thinks I've clicked a different button, one that wasn't even visible on the page, but is associated with content at the position where the clicked button was before the move. (If I don't move the element, it works fine.)
I can't seem to determine how this is happening. As I understand it, ASP.NET knows which submit button caused a postback because the button's name and value is included in the postback data. (__EVENTTARGET plays no role here and is empty.) So how can it think a different button submitted the page?
How could ASP.NET get confused about which button submitted the page?
(Sorry, it's not possible to put this page on a public website.)
I worked through this issue and here's what I found.
First of all, buttons by default are rendered as <input> tags with type = submit. The postback mechanism in this case has nothing to do with ASP.NET. The postback data includes, among other things, the name of the submit button that caused the postback along with the button's text (in the form name=text).
But ASP.NET button names, by default, include the names of all parent controls. When those controls are unnamed, they are given an ID like ctl00, ctl01, ctl02, etc. The result is that all my buttons are guaranteed to have a unique name.
The problem is when these buttons and parent controls are all created dynamically. On the postback, these controls are reconstructed in the load event but in the new order. Because the order affects the name (ctl01 vs ctl02), this means my submit button has a different name than it did when the page was originally rendered.
The result is that ASP.NET sees the wrong name associated with the submit button used to trigger the postback.

How to handle multiple popup dialogs in Web Application

What is the best way to handle multiple popup dialogs in ASP.Net Web Application? Trying I have approx 5+ popup dialogs to show in the main page. currently I am using the ModalPopUpExtender to display the first popup. Do I have to Create a (New Panel and ModalPopUpExtender) for every popup? All this code in the main page would make it very cluttered.
How about having a user control with one modalpopupextender exposing a public enum property to set the type of the popup. You can have 5 panels inside that modalpopupextender whose display/data are controlled by the enum property.
From the main page, you set the enum property before you call usercontrol.show() which will in turn call mpe.Show(); after setting the visibility on the appropriate panel.
This way you will only have one user control on the main page and all the pop up logic is contained within it.

building a server control that inherits button and giveing it other click capabilities

my problem is this:
i want to create a server control that inherits System.Web.UI.WebControls.Button
but gives it special capability, now what do i mean?
i want my button to be a confiorm button that will work like so:
renders to the page as a button of lets say cancel
after the user clicks it i want to catch the click event (within the server control)
and now after the click makeing the button not visible and makeing some kind of content placeholder (that will render from the server control) visible.
that content place holder will have 2 buttons inside of it:
yes and cancel
i want the programmer that adds this control to be able to register a function to the click event of the yes button.
and the second cancel confirmation button should make the first button appear agian.
(i know how to do this all in the client side but this time i need it all as server events)
my question is this: how do i catch the click event? i want it all to be handled inside the server control itself. so a programmer that adds this control wont have to worry about anything but just needs to register to the click event of the "yes" button
thank you
Since you want to have multiple controls in your server control you'll have to inherit from the CompositeControl class and manually add each control and manage the different controls visibility. To add the event handler, use the AddHandler keyword.
AddHandler YourButton.Click, AddressOf SubThatHandlesTheButtonClickEvent

How to reaload Dropdown control In this way..please guide

I have 2 aspx pages with C# code behind. Page one have 4 text boxes , one drop down and 2 buttons. Out of 2 buttons one if for appearing the second page as Popup ( as per system requirement. I could use here Ajax popup control , but requirement is different). So my page 2 has text box and button . on click of button of page2 textbox value will go in the database. and page will close. ok ? but same time, dropdown on the page1 should be fill come with fill up the records without refreshing the page1.some how the values in 4 textboxes should be there in textboxes... i tried on my best to elaborate problem.please guide.
You would have to use AJAX to populate the drop down list, which you can do using a web service. Another problem with this is that if you use the standard ASP.NET DropDownList control, and modify the list on the client, you may get an error because the dropdownlist expects the list provided to it from the previous load.
Alternatively, when the user closes page 2, it could call a method on page 1 that calls __doPostBack to force a page postback in page 1, so you could use server code to populate page 1.
A separate page is going to add to the challenges, it would be a lot easier to leverage teh AJAX popup IMHO.
HTH.
Seems like you have 2 pages Page1 and Page2. Clicking on a button from Page1 takes you to a popup page Page2. Then on submit of Page2 you need to refresh DropdownList on Page1 but you need PartialPostback instead of FullPagePostback.
If that is the case. You can javascript to do partialpostback:
http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/ajax-videos/video-172.aspx
edit:
To call a method from popup page you need to access method of parent page like: parent.RefreshDropDown();
Reagards.

Resources