My button click is working only the first time - asp.net

I have a classic ASP NET page on my SharePoint site with several buttons in it:
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.Controls.Add(new LiteralControl("<br/><br/>"));
this.Controls.Add(importZIPPOTBtn);
The first click on any button is perfectly firing the event, but any further click on any button doesn't fire, I can't understand why...

Consider aadding button to form1 or container element like panel inside page.
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.form1.Controls.Add(new LiteralControl("<br/><br/>"));
this.form1.Controls.Add(importZIPPOTBtn);
You can verfiy in html source, unless you add this way even literal control containing lines breaks will not be rendered.

Related

I have a table with records. No matter which View button I click, the bottom record is displayed

I have a table with a list of records. Each record has a View button. But no matter which View button I click, the bottom record (Acme6) gets opened?
enter image description here
It looks like you are sharing datasource for your list and details pages. If my assumption is correct, then you need to modify your view button event handler as follow:
// onClick event handler for View button
var rowItem = widget.datasource.item;
var listDatasource = widget.parent.parent.datasource;
listDatasource.selectKey(rowItem._key);
app.showPage(app.pages.DetailsPage);

How to click a button in Qt WebEngine?

How to click a button in the newest Qt5.7 WebEngine?
In the past Webkit, we could do this to click a button:
QWebElement button = frame->findFirstElement("input[id=search]");
button.evaluateJavaScript("this.click()");
So, how can I do the same thing with Qt WebEngine?
Thanks for any suggestion.
You need to move code that finds button to JavaScript, for example
var button = document.querySelector("input[id=search]");
if (button) {
button.click();
}
Then execute your JavaScript code with QWebEnginePage::runJavaScript().

LinkButton is not properly triggered

I'm going crazy about making this code to work. I got a simple link button that I add to a panel. When I click on the link, it's like something is trigger (whole page refresh and my link button disappear) but when I debug it, I never enter my DownloadItems function.
LinkButton linkTest = new LinkButton();
linkTest.ID = "ID";
linkTest.Click += new EventHandler(DownloadItems);
linkTest.Text = "Test";
In another page, everything is working great but I can't put my finger on it :s

Details View in Asp.net, Set it to NEW

I have a grid view on my page, and a hidden details view.
When the user wants to add a new entry, they will click a button, and the gridview will become hidden and the details view will become visible. The only problem is I want my details view to automatically be set empty in the NEW mode, without them having to click the new in the details view form.
In the RowCommand event of the gridview:
myDetailsView.Visible = true;
myDetailsView.CurrentMode = DetailsViewMode.Insert;
myGridView.Visible = false;
On button click change the mode like:
DetailsView1.ChangeMode(DetailsViewMode.Insert)

Need a postback handle from a clicked dynamic hyperlink control in ajax

The scenario...I have a list of dynamic hyperlink controls on an ajax panel that link directly to a WORD doc located on a share. Clicking any link opens WORD client side (I set the file association to do that so the IE browser doesn't try to open it instead).
LinkButtons won't work because it doesn't do a direct link to the doc from the browser and I don't want server automation or activex, since I want each client to open the doc using their own box as if they had simply clicked on the document itself.
But I need to change an image in an image control once they've clicked on the hyperlink. In other words, I need the link to sit on top of a control that does cause a postback so I can get at the posting controls ID and do my thing. I'm also trying to avoid client side scripting though I'm sure there may be a convoluted way to do that.
Here is the code in the loop that creates the dynamic link. I started with just the hyperlink control, then this code is messing with adding a hyperlink to a label, that's why it's showing as it is:
Label lblWordLink = new Label();
HyperLink hrefLetter = new HyperLink();
hrefLetter.Text = items.letterName;
hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;
hrefLetter.ID = "standardLettersHref_" + items.letterName;
lblWordLink.Text = "<a href='" + hrefLetter.NavigateUrl.ToString() + "'>" + items.letterName + "</a>" ;
tRow.Cells[1].Controls.Add(lblWordLink);
I'm looking for a way to let the link open the doc and at the same time postback. Is there a way to layer the link control on top of another control such that the link just links and the control beneath causes a postback?
32U
Fixed: the answer gave the clue. On the server, during dynamic control creation I did:
HyperLink hrefLetter = new HyperLink();
hrefLetter.ID = "standardLettersHref_" + items.letterName;
hrefLetter.Text = items.letterName;
hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;
hrefLetter.Attributes.Add("OnClick", "letterHrefClick('" + items.letterName + wordDocExtension + "')");
tRow.Cells[1].Controls.Add(hrefLetter);
then client side I pushed a value into a hidden control inside the ajax panel when the hyperlink control was clicked and forced submit:
function letterHrefClick(link) {
//alert(link);
form1.hdnLetterClick.value = link;
form1.submit();
}
After the submit, back on server side, I got the value in the Page_Load event:
string x = hdnLetterClick.Value;
nice!
update...
An even better way to do this... in the javascript postback use:
__doPostBack("hdnLetterClick", "somevalue");
then in the codebehind in the Page_Init you can do (not for button or imgbutton):
string postbackControlID = Request.Params.Get("__EVENTTARGET");
string postbackArgument = Request.Params.Get"__EVENTARGUMENT");
to get at what you need. This is better if dealing with dynamic controls so you can control state during control recreation.
If you give your link an onclick attribute, those javascript actions should also be executed when the link is selected.

Resources