From a list of names i dynamically create anchor tags on an aspx form page. The result of each is as follows with different names/IDs/titles.
From a list of names i dynamically create achor tags on an aspx form page.
<a target= href="mailto:johnbrown#site.net" onclick="updateSql(document.getElementById('PersonJB'))" runat="server" id="PersonJB" title="JB">John Brown</a>
Java function updateSql is
function update(passLink) {
/* alert("this dialogue has been invoked through codebehind."); */
document.getElementById('<%= btnUpdateSql.ClientID%>').click();
}
btnUpdateSql is defined hidden
<asp:Button ID="btnUpdateSqlt" runat="server" Text="Button" CssClass="hidden"/>
It all seems to work. except I want the click event to be aware of the different link that was clicked.
What I want to achieve: Update btnUpdateSql text with the ID or title of the passed link before called the click event in the javascript function.
How can I set the button text in the Java function? Or how can i use another hidden field?
The purpose being to update SQL table in the click event using the initials as a key.
First of all, multiple links triggering a button click event under the hood is very fragile.
Why not use LinkButton since you are posting back to server anyway.
The advanatage is LinkButton has CommandArgument and CommandName. All links can use same Common Event, and you can see which link trigger the event by looking at the CommandArgument.
If you do not plan to postback to server, you will need to redesign the application to use Ajax. It is out of the scope of original question.
Related
I have a quite complex form built with PrimeFaces 4.0 and i want to add some client-side jQuery/Javascript-Code which should be triggered if the value of any of the form input fields changes.
For <p:inputText> and <p:selectBooleanCheckbox> I can register an event handler with $(this).change(handler);
How can I register this handler for a <p:selectonemenu>? Registering the handler on the Element itself or the embedded _input-Field doesn't trigger the handler when I change the value.
Note: I do not want to set the handler directly on the Primefaces-Tag, but dynamically via jQuery.
Any help is greatly appreciated, thanks!
Found a solution:
Primefaces creates a seperate panel for displaying the options which gets displayed if the user clicks on the <p:selectonemenu>. The id of this panel is the id of the selectonemenu + "_panel". As it is a panel and not an input of any kind click() must be used instead of change()
Example:
$(PrimeFaces.escapeClientId($(this).attr('id')+"_panel")).click(handler);
Obviously, in the handler you have to switch back to the menu with something like this:
if($(this).attr('id').endsWith('_panel')){
widget = $(PrimeFaces.escapeClientId($(this).attr('id').substring(0,$(this).attr('id').length - '_panel'.length)));
I have a LinkButton that essentially toggles a menu, "show/hide".
So I am doing the show/hide logic in a javascript method called onShowFiltersClick(), that is attached as an OnClientClick event.
But how do I reach (and change) the text value of the button? It is currently being set statically in the .cs file to "Show filters". But I want to toggle this on the client side. And the changes will probably have to persist across postbacks.
But as it stands now, I can't even retrieve the string "Show filters" from the .js, trying everything both sending the button's clientID as a parameter to the javascript and by accessing it through jQuery $ and the button's css class. I then try to view all sorts of parameters, including text, innertext, value and innerHTML.
So how do I access it?
edit: Neha requested a code snippet, so I'm including one of several I have tried:
function onShowFiltersClick() {
var filtersPanel = $('.filters-panel');
var displayStyle = filtersPanel.css('display');
filtersPanel.toggle('fast');
var showFiltersButton = $('.show-filters-button');
alert(showFiltersButton.text);
alert(showFiltersButton.innerText);
alert(showFiltersButton.innerHTML);
alert(showFiltersButton.value);
if(displayStyle === 'none')
$('.price-slider').repaint();
}
This produces the following:
function (a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)}
followed by a bunch of undefined.
I have a repeater in UpdatePanel, and in it is a linkbutton that needs to set some values in a hidden div (display none) and then call javascript method that would make that div visible.
I am using ScriptManager.RegisterStartupScript and it is calling js method but the problem is that the code behind code is overwritten - code behind code is setting values for some fields from database (in the hidden div) and after it appears the fields are empty. If i click on a different button in repeater in updatepanel the div appears with the values set for a previous click. (the customer demand is that they click on a record in repeater and they can change it in a modal dialog).
how can i get the javascript method to make the modal dialog appear with the proper values?
current code is something like this in oncommand event for a repeater linkbutton
...
txtName.Text = row.Name;
ScriptManager.RegisterStartupScript(this, typeof(string), "showEdit", "showModalPanel('pnEdit')", true);
I recently had some issues with getting ScriptManager.RegisterStartupScript to work with partial postbacks using an UpdatePanel. Try switching your code to use something like this instead...
ScriptManager.RegisterClientScriptBlock(updPnl, updPnl.GetType(), updPnl.ClientID, "alert('hello world';", True)
You also may have to manually update your UpdatePanel on each click so that the hidden div gets the refreshed values. To do this, you'll have to set the UpdateMode on your UpdatePanel to Conditional and then be sure to go back and manually update it whenever you need to in your codebehind.
I want to access a dropdown asp control client id placed in the gridview.
function validate(){
var ddl = document.getElementById("ctl00_ContentPlaceHolder1_grdProducts_ctl02_ddlSelectSize");
}
I want a generalized way to access above id on a rowcommand event click of a gridview that holds a button.
And onButton click i am calling method onclientClick(return validate());
try this code,will work fine
var grid = document.getElementById(gridID);
var ddl= grid.rows[1].cells[1].getElementsByTagName('input');
You can add a marker css class to you dropdown. Than you can search for all inputs which have this class and attach to click event.
Attached event handler method has the information about sender so that you do not have to hardcode anything.
If you can use jQuery it gets really simple. I can provide you a sample code if you need
I have a repeater control that contains a hyperlink which the user will click to launch a custom aspx modal window. The hyperlink contains the "record id" value.
The user clicks the hyperlink, the code passes from code behind to javascript, which launches the custom aspx window.
How do I pass the record id parameter from javascript function so that the aspx modal window being launched can retreieve it, and run a sql query with that value.
I am open to creating a session value, a hidden html control (I tried the hidden control, but was not able to pass the value) or any other options.
Any suggestions?
From what you write, the most obvious solution would be to pass the ID as the part of the address. Like:
<ItemTemplate>
<a href="javascript:ChildWindowUrl?ID=<'%# ((MyEntityType)Container.DataItem).ID %'> >child window</a>
</ItemTemplate>