Im new in asp.net. I want to know how to fire textbox validate event. Just like as windows app textbox validate event. I enter the Product no. in asp.net textbox and if this Product no. exist in database so this Product no. information retrieve from database.
For that you have to use some jquery function.
Like this
$(document).ready(function () {
$('#<%=txtProduct.ClientID %>').blur(ShowAvailability);
});
function ShowAvailability() {
// your code
}
Easiest would be to add a search button. In code behind of the search button query your DB table and then you can print result in a label. or display a jquery modal to user.
Related
I have a c# calendar control that triggers a form submission when the date changes. It is all set up and works fine (so I don't want to switch to the JQuery date-picker).
At the moment the form submits and redirects to a confirmation page. However, I want to change this so it pops up a Jquery UI dialog (or equivalent) with some Ts and Cs that the user has to agree to (with a checkbox) before they can submit the form.
I assume the simplest way to do this is to have a div with the Ts and Cs, checkbox and submit button in a hidden div that the thickbox shows. Question is, how do I trigger the dialog from the c# date change?
Been requested to add some code - trouble is, I don't know what to add!
If I was doing this with a button click, I'd put something like:
$("#btnSubmit").click(function (e) {
//...
}
But how do I do the equivalent to pick it up from a SelectedDateChange event?
You can use ScriptManager.RegisterStartupScript for registering a script at run-time.
What you need is something like below in SelectedDateChange event code in c#:
ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID, "JavaScriptmethod()", true);
Replace JavaScriptmethod() with your javascript method or you can also write js in here too. This will execute the javascript method on SelectedDateChange event of C# calendar.
I am using Asp.Net/C# in my application.My current situation is that I am using Jquery tabs on one of my pages , I have tabs in the following order
Personal Details
Additional Details
Submit Data
Show Records
On the tab Show Records I am allowing the user to enter customer name whose records will be displayed in Asp.Net Gridview Control , The GridView is populated with the data on the click of an Asp.Net Button , My issue here is that when the user clicks the button , as it is a server control the page is refreshed and the Personal Details tab is shown and the the user needs to go to the tab Show Records to view the data in the Grid View.It shows the data from the database properly , but It is not what I need.When the button is clicked the tab Show Record should be visible.One solution I researched was to use Html button and call the function from client side.Can you guys suggest me some solution or using the html button is the best solution.
Thanks
append that code to your button click function on server-side
string script = "ShowRecordsTab();"
ScriptManager.RegisterStartupScript(this, this.GetType(), "RecordsTab", script, true);
and add this js code to your view
<script>
function ShowRecordsTab(){
$("li:last").click();
}
</script>
i have a aspx page and in which\
Add Edit Delete
ABC GRIDVIEW
DEF
GHI
on click of any side link let ABC , DEF etc the Gridview related to that is opened
the gridview is in the Web user control and i have to show the gridview in the Placeholder dynamically.
in this case the whole page is not post back only the page in which the grid view is showing is post back and show the result.
please help and suggest me that how is it possible
It seems you are using dynamically lodaed controls. For events to work, you have to recreate your control on everypostback(OnLoad), if not the event won't be fired.
http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic4
If I understand you correctly, you want to Submit the form in 'GRIDVIEW' by clicking on one of the links on the left?
You can trigger submit events through jQuery as follows:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").submit();
});
This will submit the form, but presumably, you'll want to post the form to different locations regarding on which link is clicked?
I would suggest:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").get(0).setAttribute('action', 'myCorrectActionValue'); //this works, similar commands tend to fail silently
$("#myForm").submit();
});
I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in C#.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated.
Thanks in advance.
You need to write service WCF or Webservice in server side that will receive userId and text and save it into database.
[WebMethod(Description = "Save Text")]
public string Savetext(int userId ,string text)
{
}
Second method will retrive the text from daatabase by user id
[[WebMethod(Description = "Get text")]
public string GetText(int userId)
{}
In client side do invokation using Ajax calls (Jquery)
Use this to get selected text from page: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
Then in mouseup event copy it to some HiddenField. Now you need a button or maybe AJAX call in mouseup so you can send it to server. On the server side save it to DB along with UserID and page address or ID.
On the next visit of this user to this page check in DB for entry. If it exist put the text in some hidden field. Then using jQuery get that text clientside, find it on page (using regex or something) and select it. You should remember to disregard any HTML markup while finding the text which can be tricky...
That is general way I would take to do this.
you can do that by capturing the selected text and send it via ajax call to your database.
check this example to know haw you can capture the selected text.
If you use jquerythen you will use select() function to capture the selected text
<textarea id="txt"></textarea>
<script>
$(document).ready(function(){
$('textarea').select(function()
{
var selectedText=window.getSelection();
//here put the ajax call to your webservice
});
});
</script>
I am trying to build a SharePoint 2007 web part in Visual Studio.
This web part should search a sharepoint list and display the results.
What I want to accomplish is to display the results as soon as the user stops typing, so no clicking button involved.
Probably, a combination of text_changed event and onkeydown javascript?
Any thought would be great.
This sharepoint site is "Ajax-enabled", btw.
Thanks
I would suggest using jquery and keyup:
$("input#txtid").keyup(function () {
if (this.value.length < 8)
return false;
$.get("ServiceUrl", { arg: this.value }, function (result) { $("#output").html(result); });
});
The easiest way to take care of the UI part is to use the AjaxToolkit AutoCompleteExtender se MOSS, AJAX and the AutoCompleteExtender then all you have to do is decide how you want the searching inside the web service to work
I approached this by using an UpdatePanel in my webpart. Then I added a Button (more on this later) and a TextBox to the UpdatePanel.
I also have a JavaScript class which handles all of the logic for submitting a query after the user has paused while typing their query. It contains the event handler for the onkeyup event which is attached to the TextBox:
t.Attributes.Add("onkeyup", "javascript:oSearchClass.KeyUpEventHandler(event);");
I used setTimeout and clearTimeout to handle when the class should call a SubmitQuery function.
When SubmitQuery() is called, it makes the TextBox read only (so the user can't type anything while it is querying) and then "clicks" the button using click(). Since you're using a normal Button, you can handle the Button.click event like normal to re-query the list and display results.
If you don't want your user to see the button, you can simply put it inside a span WebControl that is hidden.
Have a look at this sample, it adds 'search as you type' to the standard SharePoint search box.
Automatically add ‘Search As You Type’ to every SharePoint page using Infuser.