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
Related
There is an event onSelectedIndexChange for DropDownList in ASP.NET which triggers when a selected index is changed for a dropdown.
I have encountered a situation where I need to trigger similar kind of event when SelectedIndex of DropDown does not change upon selection.
I am totally puzzled what to do in such a case?
Any help/references will highly be appreciated.
Thank you.
I think that is normal. The event is SelectedIndexChanged and you said you selected the same item that was previously selected before. So the index remains the same, not changed, and the event won't fire. May be you look at OnClick.
The issue is that you have not changed the index when you clicked the second time, so the dropdown is still waiting for you to change it
Assuming you have another server-side control on your page that causes a postback, you could write a routine in the postback event for the other control that compares the current selection with the previous selection and fire a custom-event (or the routines you want to happen) if the value has not changed.
That said, I have to imagine there's an easier way to accomplish the overall goal you're trying to achieve, but you'll have to be a little more specific in your question.
UPDATE
I have to assume that you are using the value from the dropdown when you are processing the form. Why not start off with the dropdown hidden and the linkbutton shown? Just select a default from the dropdown list and allow the user to change it as needed.
Here's a fiddle showing that behavior: http://jsfiddle.net/rjaum/
That's fairly easy.
You can achieve this using javascript/jquery/server side code etc. Assuming user does click the control.
Something like this on pageLoad
PageLoad()
{
YourDropDownList.Attributes.Add("onclick","javascript:CallHelloWorld();return false;");
}
Then on server side you can decorate a method with WebMethod attribute
[WebMethod()]
public static string HelloWorld()
{
return "Hello foo";
}
On your client side aspx you can use jQuery to call your webmethod
<script language="text/javascript">
function CallHelloWorld()
{
// Call HelloWorld webmethod using jQuery $.ajax
}
</script>
Edit
You can use a radiobutton list instead of dropdownlist. That way, on client side you can check the event when the radio button is clicked that it is checked or not (if its checked fire your event).
Edit
Also try looking at this thread if you want to use dropdown list specificallyFire event each time dropdown list is selected with JQuery
assign an a event handler to the selected index changed event and set autopostback to true
in markup
or code behind
mydropdownlist.SelctedIndexChanged += NameOfMethod
the handler is then defined like this
protected void NameOfMethod(object sender, EventArgs e)
{
//your code here
}
update
by definition the selectedindexchanged event would only fire when the index changes. if you want to force the postback that will require some javascript. here is an example of how to do that with jquery
$(function() {
$('select').change();
});
In my javascript, I have the following line:
__doPostBack('MyPanel', MyParam);
In my code behind, I use MyParam to query a database and bind the result to a gridview that's inside the MyPanel updatepanel. The updatemode of the updatepanel is set to conditional and in the postback part of the code I have MyPanel.Update();
The updatepanel works fine when I'm doing sorting and paging; only the panel is refreshed. However, when I trigger the updatepanel with my javascript, I see the traffic in firebug showing that the entire page is being refreshed.
What's the solution?
Thanks.
My assuption: your update panel is located inside the naming container, so its id in the client side will be a little bit different from the server side ID. This means you pass the wrong __EVENTTARGET parameter to the client side __doPostBack function and your partial postback became full(meaning not async).
So changing your client code to:
__doPostBack('<%= MyPanel.ClientID %>', MyParam);
should solve the problem.
BTW, you could get the second(MyParam in your code) parameter from the server side:
var arg = Request.Params.Get("__EVENTARGUMENT");
This is probably a simple question.
I use ASP.NET ajax toolkit and Jquery. I want to call a server-side function/method from Javascript and have it update a control. Can i do this?
Client-side
send_request(foobar,args);
Server-side
private void foorbar(){
Label1.Text = "updated";
}
Do you want it to fire a server-side method and update a server-side control on the page? You can create a ASP.NET UpdatePanel, let's say there is a button1 inside, and from your JQuery code, write this.
function OnClick()
{
__doPostBack(button1.ClientID, "argument")
}
and in your server side code, Page_Load event, you will find the EVENTTARGET and EVENTARGUMENT in the REQUEST variable, which contains the information you just postback, you can then update the control in the UpdatePanel itself as long as the control is within the UpdatePanel, it will be handled properly by ASP.NET AJAX.
More details here
http://www.dotnetspider.com/resources/16920-Post-back-gets-demystified-doPostBack-defined.aspx
Yes that can be done Client Callback
You could take a look at ASP.NET Page Methods.
jQuery.ajax({
url:'url to call', //usually webservices in asp.net
dataType:'json',
type:'POST', //(asp.net werbservices by default accepts POST request only)
success:function(data){
//do some thing with this data, like will dom elements etc
}
});
#smkngspcmn:
I placed everything inside an update panel and did something like $('#Year').change(function() { __doPostBack("submit", ""); }); That does do a full post back without Ajax. What am i doing wrong? Should i place the above script inside the update panel as well?
The first argument to __doPostBack() should be the UniqueID of a server-side control inside the UpdatePanel. For example, you can put a hidden button inside the UpdatePanel:
<asp:Button ID="HiddenButton" runat="server"
style="display:none" OnClick="HiddenButton_Click" />
When the button is rendered on the page, you can take the name attribute of the <input type="submit"> element that represents the submit button and use it for the first argument to _doPostBack(). In this way, whenever your script runs it the UpdatePanel will make an asynchronous postback and the HiddenButton_Click event handler will be fired.
I'm trying to refresh update panel via Javascript:
__doPostBack("<%=upMyPanel.ClientID %>", "");
But somehow its controls are all empty. On other hand they are all filled when I click any trigger control.
How can I fix this?
thanx.
AFAIK the UpdatePanel doesn't really postback, so your postback should be using a control that is registered for postbacks (i.e. the trigger control you speak of).
__doPostBack("<%=btnMyTrigger.ClientID %>", "");
The UpdatePanel has no client-side API; third party update panels typically do but not the MS one... You could try __doPostBack() as mentioned and target a control that posts to the server (like a button).
Try making the update panel mode to always to see if that works properly with __doPostBack. Also, try the UniqueID instead of the ClientID.
Short version
All I need is that, in a ModalPopUp, when the DoubleClick event of a ListItem fires, the click event of my OK button should be executed.
Detail
I have a ModalPopUpExtender, which hosts a user control. The user control has an OK and a Cancel button. Along with that, it has a dynamic ListBox added to it. So far, I've considered the following possible solutions:
Use Ajax.Net. But, I cannot afford to have a WebMethod.
Use a ClientScriptCallBack. This will need a lot of JavaScript, since I have made almost every control dynamic.
Is there any other way apart from using an UpdatePanel?
Have a look at this way using __doPostback
calling a VB.net function from javascript