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>
Related
I have a homepage with a register button. When clicked it displays a hidden div where the form is. I have a "Register" button in one of my inner pages of my website. Whenever it's clicked I want it to open the homepage and display the hidden register form without it being hidden. How can I do this?
As #Barmar commented, a way could be to pass a parameter to the URL
Another possibility is to use HTTP referer
var x = document.referrer;
and checking on document.ready if you should hide or show your registration form, depending on referrer value.
Remember that HTTP referer is totally client side managed, so it could be hacked (if important in your case)
use css in your hidden <div id="reg"> display:none;
while click a link or button use onclick="showDiv();" to show that div
in js function
showDiv(){
document.getElementById("reg").style="display:block;";
}
first adding id on within <a> just like
and then use this script
$('#atagId').click(function() {
var someId = $(this).attr("id");
window.open('SECOND.html/#'+someId);
});
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.
Here is the problem:
I have a page e.g www.app.com/home and I have some windows that are added in a slide way to the DOM via jquery. One of those windows has the functionality of looking into a gmail account for contacts.
This is done in this way:
User is in the home page.
Clicks the search Friends button, and a window with many options
slides in (added by jquery, rthe content is in another .gsp)
Clicks the option gmail and it redirects to googles oauth,
permissions and account selection, where he must accept the access
to his/her contact list.
Once accepted, it redirects to my home page again, where I have a
var to know if its the callback from google, so I ran the script
that shows the popup again.
The problem Im having, is that from the home page itself, I can access the model passed by the controller that has the ${friendList}, but when I add some code to the popup window, the ${friendList} is not detected.
I have used grails render templates to solve this problem in the past. You can have a hidden div that jquery unhides when it is popped up. e.g
<div id="theSlideWindow" style="display:none">
<g:render template="gsptemplate" collection="${friendList}" var="myfriend" />
</div>
Now when the button is clicked, jquery will unhide the div and animate it however you are animating it. Now this is not very efficient depending on the size of friendList because it is loaded with every refresh.
But you can still make jquery load work by doing the following:
add user id to a hidden input.
<input type="hidden" value="${userid}"/>
use jquery so send the id as a param:
$('button').click(function() {
var page = "gspurl/show?userid=" + $("#hidden").val();
$("div").load(page, function(response, status, xhr) {
//do something here
});
return false;
});
In your gsp use userid to load friendList.
Another alternative would be to use a controller that returns html or json instead of a gsp.
Obviously, there several different ways of passing friendList around but hope this gives you some ideas.
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.
There are 3 buttons on a web page. On clicking each button a same popup window (say window1) opens up. Now there is another button on this popup window (window1), which further opens up to another popup window (say window2). On selecting some value from the 'window2', that value is passed onto the 'window1'. There is a 'Find' link on a 'window1', which calls a javascript function 'clicked()':
<head>
<%
Dim command
command = Request.Form("hid");
Response.Write(“Value” & command); -- The value is not printed (Reason found after
analysis that may be because the form is not submitted
successfully)
%>
function clicked()
{
document.form.hid.value='FIND';
alert("before"); -- This message box appears
**document.form.submit();** -- after a lot of analysis the conclusion is that
this submit statement stops working (as on the status
bar 'Opening https:.....File1.asp?form=...' is not
displayed when 'after' message box appears
alert("after"); -- This message box appears
}
<body.......>
<% if command = "FIND" then
Response.Write ("Inside Find"); -- This message is not printed.
// some functonality
%>
<form ....>
<input type="hidden" name="hid" value="">
</form>
</body>
This full code works fine on my machine. But this code does not work properly when run on the client-side!, although the same server and the same deployed application is being accessed. There is no particular sequence/scenario but for eg.
When say button1 clicked->window1 opens->window2 is opened->value selected->returned to window1->Clicked on Find-> clicked on Ok->returned on the main page.
Then repeated the same scenario for say 3rd button.
(Till now 'Find' link works fine).
Now repeated the same scenario for 2nd button and here 'after' message is obtained but 'inside Find' is not printed!!
The document object doesn't have a form property.
The code only works if you have the attribute name="form" on the form, and only if there is a single form with that name on the page. That is a bad name for a form, as there are other objects in the DOM that actually have a form property (i.e. fields in a form).
You should give an unambiguous name to the form, and use the document.forms collection to access the form instead of relying on that the form is added to the document namespace.