I have a child aspx page in an iFrame. There are a few textboxes, which are populated in the page load event.
There is also a LinkButton which the user clicks when s/he is finished editing the fields. There are some javascript functions and other things going on, so a full postback (ie: asp button) is out of the question.
Problem is, I need to reference the textboxes NEW values (user changes) after the linkbutton is clicked.
Is there any way to do this?
Thanks,
Jason
EDIT:
After playing with the interface a bit further, I realized the Page_Load event was firing as soon as the LinkButton was clicked. Of course this is where the data is initially loaded, so any changes the user made is immediately written over. Current plan of attack is to create an IsLoaded cookie value and check if true before the mentioned code executes. If anybody has a better idea, please let me know!
Thanks,
Jason
You can use jQuery to grab the textbox value on click of the button.
<script type="text/javascript">
$(document).ready(function() {
$('.btnSubmit').click(function(e) {
alert($("#txtName").val());
});
});
Then you may pass this textbox value to a server side method by calling it using jQuery AJAX. See the link below .
http://weblogs.asp.net/karan/archive/2010/09/12/calling-server-side-method-using-jquery-ajax.aspx
You want to access the new textbox values from the parent or from within iframe which has that webform opened?
Related
i have a textbox on a page, now whenever any age number is entered in that page, that page should be loaded in my datalist, i have created rest of the thing, but i am not getting how to trigger the textbox onkeydown event from asp.net, i know working with that from javascript, but the problem is i have below things done in that function:
it applies the currentpage value to the static variable from textbox
it binds the datalist
it enable disable the next previous buttons accordingly
and i dont think this i can do from javascript, anyone have any resolution, how this could be achieved from server side, onkeydown event
You can capture the keydown event in a javascript function then do a AJAX call to the server. If this does not suit you, then you could try manually do postback in javascript.
So in your textbox:
mytextBox.Attributes.Add("onkeydown", "return doDataListBind()");
Now in the javascript function:
function doDataListBind()
{
__doPostBack("myTextBox"); // etc, etc
// some other code here...
}
More info can be found here:
http://geekswithblogs.net/mnf/archive/2005/11/04/59081.aspx
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
Try looking into or using either:
AJAX Control Toolkit, or
JQuery Autocomplete Plugin
Alternatively you could try to call _postback() function from a client side event/function for your textbox in javascript
I have an ASP.NET web form on which I'm displaying a list of database items via user controls, generating the user controls dynamically - working fine.
Also on the page, I have an asp:dropdownlist filled with items that can be added to this database list. Along with this dropdown I have a button 'ADD'. My intent is that the user chooses and item, clicks add, and then the list of user controls on the form will include this new item.
I have all this working.
My issue is that the user control has a button 'DELETE', which removes the selected item from the list. That works, EXCEPT when I add a new item. Because my 'add' button event is always fired after Page_Load, even if I regenerate the list of user controls, the internal user control click events won't fire because the controls weren't created as part of Page_Load.
I need to know what I'm doing wrong, or best practices here, any advice. I tried to be precise in the description of the problem, but if I've not succeeded, let me know and I can add more details.
SIMPLE RESTATE: I need to know how to add a dynamically created user control to a page via a page button click event, and still have the user control internal click(etc) events firing.
Thanks for any help.
EDIT: Based on the feedback from the gentlemen here, and doing some further research related to their suggestions, I ended up implementing a solution based on what's presented on this page:
http://ryanfarley.com/blog/archive/2005/03/11/1886.aspx
Here's a snippet showing how I dealt with this. This snippet resides in my PreInit event handler. Not exactly an elegant weapon for a civilized age, but sometimes a blaster is all you've got to use.
'Look to see if button for adding a new client number has been
'clicked. If so, call the sub to add the item NOW, so that it
'is able to have it's internal click events fire.
For Each control_string As String In Request.Form
Dim ctl As Control = Page.FindControl(control_string)
If (ctl IsNot Nothing) AndAlso (ctl.ID = "cmdAddClientNumber") Then
Me.AddClientNumberToList()
Exit For
End If
Next
On the button handler, you initially add the UserControl to the Page. OnPreInit (which will next be fired when the user clicks Delete on the UserControl), you should re-add the UserControl - so that it exists, and can handle the Delete button event.
You will need to devise your own state tracking mechanism to determine that you need to add the UserControl during PreInit. I generally use ViewState, as evidenced by this seemingly similar post.
Similar question:
How to create and use custom control with UpdatePanel added to the page programmatically
Dynamic control should be re-added to the control tree OnPreInit, see documentation:
PreInit - Create or re-create dynamic controls.
ASP.NET Page Life Cycle Overview
I'm using telerik radgrid control with following layout:
I'm curious if anybody can provide general guidance in what approach I should take to reliably update user control that initiated popup window action?
On radWindow OnClientClose event you can write up javascript code to reload the user control which initiated the action.
I had a somewhat similar requirement sometime ago, where I needed to rebind the grid after closing the radWindow and used the onclientclose
function RefreshGrid() {
var masterTable = $find("<%= GRIDNAME.ClientID %>").get_masterTableView();
masterTable.rebind();
}
In any case, I suggest you to look into the javascript api on how to update the user control(depends on what you want to update on the user control).
So here is how I've solve the problem:
I created "hidden" button on each tab's user control that needs to be updated and passed in button client id when opening popup. this button client id is stored as java script variable and when user close modal rad window I execute code that simulate hidden button click:
$find(myStoredButtonClientIdJSVariable).click();
That in turns execute proper user control server side code and my grid is properly refreshed.
Hope somebody might have some benefits reading this.
I have 3rd party user control (a captcha control), which has a captcha image, a text box within it.
I am using the above user control in my webpage. I have a 3 submit buttons on my webpage (Validate Captcha, Submit Page, Add User). When I click the Validate Captcha submit button using the mouse, I am validating whether captcha is empty and showing a javascript alert.
The problem comes when I enter the valid captcha text in the textbox and hit enter key when the cursor is in the textbox. The page just refreshes. I am unable to add keypress event to textbox and call Validate Captcha button event as I am using the 3rd party user control which I cannot modify.
Also, Page.ClientScript.RegisterHiddenField(...) will not work in my case as I have two other submit button inside the same page.
Only option left is to enclose these in panels and set default button.
Please let me know if anyone has any better options for achieving this.
Greetings! I too use alot of third party controls. The thing to remember about these controls, it that in the end they just emit HTML. This means you can use the DOM to access and attach event handlers such as onKeyPress. The trick is to identify how your control creator named the control you are looking for, in this case a {textbox}. The easiest way to achieve this is to simply run the page and view the page source. It is there that you can find the name as it is rendered and sent to the browser, after that all you have to do us use document.getElementByID to get the object and setup your handler
Example:
<script>
//Place this AFTER your textbox control is declared in the HTML
//Get the textbox
var textbox = document.getElementById('nameOfRenderedControlHere');
//Assign the event handler and function you want it to call
textbox.onclick = function() { validateCaptcha(); };
function validateCaptcha()
{ //Do your Stuff here }
</script>
That should be it..havent tested, let me knwo if you run into questions.
Put the captcha in its own <asp:Panel> and add a DefaultButton property for the panel with the ID of the captcha's submit button.
I have a page with a GridView on it that launches a popup, using Javascript. The user then selects an item, that updates the data connected to the GridView and closes the popup.
How do I refresh the first (ie the Calling page) so that I can refresh the data shown in my Gridview?
Try this inside your popup:
<script>
window.opener.location.reload()
</script>
That should refresh the page that opened the pop-up
If you simply need to trigger a postback on the calling page, this should work:
<script>
window.parent.document.forms[0].submit();
</script>
By explicitly submitting the form, you avoid the warning that appears if you just refresh the calling page.
If you need to trigger an OnSelectedIndexChanged event on the GridView during the postback, then things are a bit fiddlier, but you should be able to do it by calling window.parent.document.__doPostBack() with suitable arguments.
Here is the Solution:
Dim CloseScript As String = "<script language='javascript'>function closeWindow(){ window.opener.document.forms[0].submit();window.close();}closeWindow();</script>"
In .NET 2.0 you have to add this to the page to register above Javascript:
'register with ClientScript
'The RegisterStartupScript method is also slightly different
'from ASP.NET 1.x
Dim s As Type = Me.[GetType]()
If Not ClientScript.IsClientScriptBlockRegistered(s, "CloseScript") Then
ClientScript.RegisterClientScriptBlock(s, "CloseScript", CloseScript)
End If
Does this avoid the 'page cannot be refreshed' message
window.opener.location = window.opener.location;
(sorry I would have just left a comment on TonyB's post but I don't have enough SO points, so I'm not allowed... :(