ListBox fire onclick Event - listbox

<asp:ListBox ID="ListBox1" runat="server"
AutoPostBack="true" OnSelectedIndexChanged ="button_click"
>
<asp:ListItem Selected="true">Item 1</asp:ListItem>
<asp:ListItem >Item 2</asp:ListItem>
</asp:ListBox>
I have this code in .aspx file
But I need to fire onclick Event ,not when I only change an item from Item 1 to Item 2. so what should i do? There is no onclick event.

Related

Invoking multiple instances of the same jQuery UI dialog

I have a jQuery UI dialog with several tabs, sometimes, I need to pop up one of those tabs as a separate dialog (atop of tabbed initial dialog), so, can I achieve this by re-using the same dialog?
(of course with a bit run-time customizations, JavaScript/DOM HTML manipulations, but with the same <div></div> template initially defined and with the same HTML FORM elements IDs)
This is not the optimal solution, but could be an approach of what should you do.
HTML:
<div id="dialog" title="Basic dialog">
<div class="dtabs">
<ul>
<li>First
</li>
<li>Second
</li>
<li>Third
</li>
</ul>
<div id="tab1">
<p>First!</p>
</div>
<div id="tab2">
<p>Second!</p>
</div>
<div id="tab3">
<p>Third!</p>
</div>
</div>
</div>
<input value="Tab 1 on Dialog" type="button" alt="1" />
<input value="Tab 2 on Dialog" type="button" alt="2" />
<input value="Tab 3 on Dialog" type="button" alt="3" />
Javascript:
$(function () {
// Dialog without autoOpen just to hide it from viewport
$('#dialog').dialog({
autoOpen: false
});
$('input').click(function () {
// Clone the dialog and append it to body
// Get "tab" number to know which tab should I set as active later
var d = $('#dialog').clone().appendTo('body'),
tab = $(this).attr('alt')-1;
// Assign "dialog" behaviour and remove it when I close it
d.dialog({
autoOpen: false,
close: function (e, ui) {
$(this).dialog('destroy').remove();
}
});
// Tabs inside my dialog has "tabs" behaviour by JQueryUI
d.find('.dtabs').tabs({
active: tab
});
// Open up!
d.dialog('open');
});
});
http://jsfiddle.net/franverona/k7cuH/
Let me explain you what I did:
I create my dialog in pure HTML and using JQueryUI assign it a dialog behaviour.
Every button has a property that will tell me later what tab should I open in my future dialog.
When user click on button I clone my previous dialog, append it to body and get "tab" attribute. Then I assign it a dialog behaviour without autoOpen and with a function associated to close event to remove it from DOM (to avoid multiple dialogs on my HTML body).
Before open, I assign a tabs behaviour to all the content inside my recently created dialog (look that I'm using find function) and set as an active tab the correct tab using tab property retrieved before.
Now I'm ready to open my dialog with all set up.
I repeat: this isn't an optimal solution, but should work as a prototype of later development iterations.
Happy coding!

Repeater.Items only populates in Button click event when I DataBind in that event, but all textbox inputs are empty

I have a repeater that is databound to a SqlDataSource
<asp:Repeater runat="server" ID="Repeater" DataSourceID="SqlDataSource">
<ItemTemplate>
<asp:HiddenField runat="server" Value='<%# Eval("Code") %>' ID="Code" />
<asp:TextBox ID="NumberNeeded" runat="server" Text='<%# Eval("Needed") %>' /><br />
</ItemTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="submit" Text="submit" OnClick="submit_Click" />
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="rtvFiltered" SelectCommandType="StoredProcedure">
<SelectParameters>
</SelectParameters>
</asp:SqlDataSource>
I want to iterate over the repeater and get the value in NumberNeeded in submit_Click
protected void submit_Click(object sender, EventArgs e)
{
this.Repeater.DataBind(); //comment this guy and this.Repeater.Items has no items
foreach (RepeaterItem item in this.Repeater.Items)
{
String code = ((HiddenField)item.FindControl("JournalCode")).Value;
// below fails because "NumberNeeded" control doesn't have the Text input by the user.
int numNeeded = Int32.Parse(((TextBox)item.FindControl("NumberNeeded")).Text);
// Doing other stuff with numNeeded
}
}
The repeater displays its items perfectly on the page, but when I click the submit button, this.Repeater.Items is empty (unless I call this.Repeater.DataBind() in that method).
I've tried explicitly data binding Repeater in Page_Load and Page_Init within and outside of a !Page.IsPostBack check, and everytime I either get no Items, or no Text value.
I have gotten an almost identical setup to work in the past, on a page without a master page. I've also noticed that this.Master.EnableViewState is false in the submit_Click method, no matter if I set it to true in Page_Init or Page_Load. this.EnableViewState is true.
As you state, you shouldn't need to call DataBind() in your code behind, so the problem may be with the data retrieval. Does your stored procedure take any parameters? Have you tried adding CancelSelectOnNullParameter="false" to your SqlDataSource?
It was the EnableViewState setting on the master page.
In the Page_Load method of the master page this.EnableViewState was getting set to false. I changed it to Page.EnableViewState and everything worked.
this.EnableViewState = Page.EnableViewState; // add to Master page Page_Load method
do'h

How can I use Knockout's click binding with jQuery Mobile's vclick event?

In my jQuery Mobile + Knockout.js application all clicks have the 300ms delay before the synthesized 'click' event fires.
Is trying to use jQM's 'vclick' event the right way to address this? If so, how can I accomplish that with the knockout click binding? Should I be using 'tap' instead?
Like fab says, the way to do this is with knockout's event binding:
<!-- ko foreach: widgets -->
<li>
<a data-bind="event: { vclick: $root.clickWidget }">
<b data-bind="text: $data.name"></b>
</a>
</li>
<!-- /ko -->
Thanks!

how to call a struts2 action on click of a row from jQuery grid

i have a jsp page where i am displaying my books detail in Struts2 jquery grid.
Now i want to call an action and pass rowid as a parameter to the the action class on the click of a row from my Jquery grid. And i also i want to specify the target of my div to refresh after calling my action.
These stuffs i know nicely through <sj:submit target="targetDivToRefresh" formId="form2" button="true"/> but i don't know how to do these task "when users click a row from my struts2 jquery grid".
Please help me to solve this issue.
my jsp page
<sjg:grid
id="bookgrid"
editurl="%{bookediturl}"
navigator="true"
editinline="true"
navigatorSearch="false"
autowidth="false"
width= "1550"
viewrecords="true"
navigatorRefresh="true"
navigatorDelete="true">
<sjg:gridColumn name="id" index="locationId" title="ID" formatter="integer" sortable="false" key="true"
search="false" editable="true" hidden="true" />
<sjg:gridColumn name="authLastname" index="authLastname" title="AuthorLastname" sortable="true" search="true" editrules="{required: true}"
editable="true" edittype="text" />
</sjg:grid>
try this:
$(function(){
$.subscribe('rowselect', function(event,data) {
alert(event.originalEvent.authLastname);
$("#targetDivToRefresh").load('your-struts2-action');
});
});
UPDATE
$("#targetDivToRefresh").load('your-struts2-action');
Reference Link: Struts2 jquery plugin showcase
Please make sure this event will be triggered, if you click on a row, i added test code alert() to make sure, it has been called during the event. there is still a thing, that i have to tell, you have to register your selectrow event in your <sj:grid> tag using onSelectRowTopics="rowselect"
UPDATE
$("#targetDivToRefresh").load("<s:url value="your-struts2-action"/>"+"?id="+event.originalEvent.id);

OnBlur event not being fired on clicking of a commandButton?

I have developed a composite component as follows...
<composite:implementation>
<div class="numericBox">
<h:inputText id="txtInput"
size="#{cc.attrs.maxLength}"
converterMessage="#{cc.attrs.converterMessage}"
validatorMessage="#{cc.attrs.validatorMessage}"
required="#{cc.attrs.required}"
requiredMessage="#{cc.attrs.requiredMessage}"
minlength="#{cc.attrs.minLength}"
maxlength="#{cc.attrs.maxLength}"
value="#{cc.attrs.value}">
<f:ajax event="blur" render="#this err"/>
<f:ajax event="blur" render="#{cc.attrs.renderParent}" disabled="#{empty cc.attrs.renderParent}"/>
</h:inputText>
</div>
<h:panelGroup id="err">
<utils:fieldError_right id="errText" group="#{cc.clientId}-txtInput"/>
</h:panelGroup>
</div>
</composite:implementation>
And I have a command button like below..
<h:commandButton id="btnNext" styleClass="btnNext" action="#{someBean.next}"/>
Now I am using the component in the following way...(just showing the bare bone representation)
<util:numericInput label="Label" value="#{somebean.number}"
maxLength="2" optional="true" renderParent="-vehVal"
/>
<h:panelGroup id="vehVal">
<util:amountInput label="label2" value="#{someBean.nubmer2}"
rendered="#{someBean.number > 0}"
required="#{someBean.number > 0}" />
</h:panelGroup>
So basically I want to render the "amountInput" component when ever user has entered some value > 0 in the "numericInput" component.
It works fine when I enter some value in the first field and click some where in the browser. But if I enter some value in the field and click on the next button directly it takes me to the next page, without validation (rendering) the next field.
All I can understand is the onBlur event is not fired when I click on the next button. Why ?? Is there any solution??
It may be that the event is fired, but the form is also being submitted, so the next view will be rendered and you'll miss the result of the ajax event.
You may have to use a more immediate event than blur, such as keyup. Additionally, you could conditionally disable the button if someBean.number is > 0 and someBean.number2 is empty.

Resources