Dynamically created link button event not firing after page index change - asp.net

I have dynamically created link buttons in grid view and assigning event for it,
lb.Click += new EventHandler(LinkButtonClicked);
Event is not firing if I change page index change (on click of '2' below grid view) and click on link button present in grid view.
It is working fine if I do not change the page index i.e. without clicking on '2' of grid view, clicking on link button present in grid view
I am not able to find out reason for this. Please help
Thanks in advance!

I think it is better to create the linkbutton inside markup in a grid template column.
if you have to do it in code, try to unsubscribe the event handler then subscribe again:
lb.Click -= new EventHandler(LinkButtonClicked);
lb.Click += new EventHandler(LinkButtonClicked);

Related

How to use CustomButton to change QWizard page in Qt?

I have a QWizard with 2 custom buttons (on top of the Back\Next buttons).
I wish that a click on my custom button will change to another QWizardPage.
How do I do that?
Thanks
That would be doable by connecting the custom buttons clicked signal with a slot which handles moving to next page.
QWizard wizard;
wizard.setButtonText(QWizard::CustomButton1, "Custom button");
wizard.setOption(QWizard::HaveCustomButton1, true);
QObject::connect(&wizard, &QWizard::customButtonClicked, [&]
{
wizard.next();
});
The code above would create a wizard with a custom button which would function like the default "next" button. If you want to create a dynamic (as opposed to linear wizard which it is by default) you would need to reimplement QWizard::nextId(). Please see:
https://doc.qt.io/qt-5/qwizard.html#nextId

How to make pop-up data reflect selected record?

The case:
I have Activities as datamodel.
I have set Activities to have many-to-many relationship with themselves to represent a Parent / Child relationship.
I have set up an accordion widget. Each row of the accordion contain basic data about the Activity record + some buttons.
I have set one of the button's onClick functions to open a popup, which allows me to edit the Activity detail in a form.
When I click a different record from the same accordion, the form from the popup reflects the data in the selected record.
The problem:
I have nested accordions which represent the "Child" Activities of the Parent Activity.
I have also added a similar button, which opens a popup. I can open the popup, which targets the child records, but cannot make it open the specific record, from which I pressed the button.
So the popup open by default on the first child.
Please help - how can I make the popup change naturally to reflect the datasource / selected record of even nested datasources?
What I tried:
In order to try and make to popup work I have tried to set the datasource based on the relationship:
Activities: Sub_Activities(relation)
This works to the extent of showing the related items, but popup content does not dynamically change on clicking a different child record or clicking the button from a different child record.
In both cases what is shown is the first child record.
What I understand is that you have a set up in which you click a button and a popup shows. The popup should let you view/edit the record referenced in the row where the button is. If that is the case, then probably you already have almost everything setup for the next thing to work. First, add a string custom property to the popup and name it selectedKey. Then, on the onClick event of the button that opens the popup, add something like this:
var key = widget.datasource.item._key;
app.popups.MYPOPUP.properties.selectedKey = key;
app.popups.MYPOPUP.visible = true;
Now, go to the popup content and add the following on the onAttach event handler:
var key = widget.root.properties.selectedKey;
widget.datasource.selectKey(key);
This is the general idea of how to make it work; However, in order for it to work, your datsources in the widgets should be properly set up. Good luck!

With the Ajax Control Toolkit, how would I go about programmatically creating an accordion control that is resizeable and drag/droppable at runtime?

I was trying to generate a resizable and drag/droppable ajax control toolkit accordion control programmatically, but am running into some problems.
First, can it be done?
Second, my approach is not exactly working.
I have a button that, OnClick, is supposed to create the accordion. So I create the accordion. Add an accordion pane to it. Add a combo button to the accordion pane. Then add the entire accordion to the Ajax Panel. My event handler follows.
protected void btnTest_Clicked(object sender, EventArgs e)
{
//Generate the accordion
AjaxControlToolkit.Accordion acc = new AjaxControlToolkit.Accordion();
//Generate a single accordion pane
AjaxControlToolkit.AccordionPane itm = new AccordionPane();
//Create and add a control to the pane
AjaxControlToolkit.ComboBoxButton cbbtn = new ComboBoxButton();
itm.Controls.Add(cbbtn);
acc.Panes.Add(itm);
//Add resizable extender to the accordion. Only did resizable for now.
//One step at a time.
AjaxControlToolkit.ResizableControlExtender extResizeLocation = new AjaxControlToolkit.ResizableControlExtender();
extResizeLocation.TargetControlID = acc.ID;
extResizeLocation.Enabled = true;
//Add accordion to update panel and update.
UpdatePanel1.Controls.Add(acc);
UpdatePanel1.Update();
}
What I get when I press the test button is what appears to be a minimized button without text generated under the test button. I have no clue what to do.
Appreciate the help
Dynamically added controls are typically supposed to be added during init or preinit event of the page. That may be a complication, since you are doing it after load.
The key is to make sure the $register method on the client for the accordion is occurring. This is what initializes the client-side features of the AJAX component, and starts the lifecycle. I don't know if it happens for dynamically added controls...
You may want to look at the JQuery UI Accordian widget and use the draggable/droppable interactions.
You could use server side code to create an block and apply the jQuery interaction.

JqGrid ask for new fields on click custom button

I have added a custom button to the navigator in my jqgrid and i am wondering how can i ,when i click on the button, show a dialog with the same style as the edit dialog and ask for some especific fields that are not included in the colModel. Those field would be to be sent to the server when clicking on ok button.
Any ideas?
Thanks in advance.
Carlos.
You can display the "Edit" dialog using editGridRow method. In the second (properties) parameter of the method you can include your custom beforeShowForm event handler which can make any modifications in the dialog.
See last demo from the answer for an example. The demo has the line
$('<tr class="FormData" id="tr_AddInfo"><td class="CaptionTD ui-widget-content">'+
'<b>Additional Information:</b></td></tr>').insertAfter (nameColumnField);
inside of beforeShowForm.
If the information which you need to show in the dialog are from the hidden column of the grid you can use simplified way which you find here. The main idea in the solution is that jqGrid include in the form dialog all hidden fields, but the corresponding row is hidden. So it is enough just to show the hidden row.

jQuery dialog serving multiple button's click event handller

I have a scenario where...
1.) Have created a div with a dropdown list and ok, cancel button
2.) On document ready - registering div created on step 1 into a jQuery dialog
3.) on a javascript button click - I am opening this dialog box.
4.) Now, the problem is - the jQuery dialogbox which I have created, needs to be used by other button clicks as well on same page. Now, my div's (which is a dialog at runtime using jQuery) ok button click is already engaged with a javascript function (button1 click) and I can not associate other button's click events with it - thus stuck up here and have no clues or hit to resolve this.
Anyone have faced this issue in asp.net, jquery earlier? Can someone provide a guidance?
Why you cant associate another event?
buttons will have different id. Is it?
$('#button1').click(function() {
alert('Handler for button 1 .click() called.');
});
$('#button2').click(function() {
alert('Handler for button 2 .click() called.');
});
Is this not possible in your case.?
Options:
1) disassociate the click handler when the function opens the div, then later in the function of opening the div associate a click handler to the button.
2) create multiple buttons toggle them all hidden, associate the click handler to each button you want. When the div is opened do a check to see which button to toggle to visible.
3) create no buttons but have a function create the button on the fly. When the div is opened, create the button for that div by calling the function and passing in a code telling it which button to open and what to associate to the click handler (this can be stored in an array and all that is passed in is the key).
Depending on the application, I have used all of these methods. The last one can have a twist that allows it to call an ajax server based application to get the button text and functionality (stored in a database), this saves you from having to load an array with button data, and also allows for easier expansion of the application.

Resources