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>
Related
I am using below tutorial to create image check box
enter link description here
it works properly but once page post back it lose the checked element and cannot retrieve it .
is there any solution for this issue?
This is absolute normal if you not save the post back somewhere and then render again the controls with the one that is selected with that class active, the rest controls with out that class...
See the javascript code from your page:
$(function () {
$('.btn-radio').click(function(e) {
$('.btn-radio').not(this).removeClass('active')
.siblings('input').prop('checked',false)
.siblings('.img-radio').css('opacity','0.5');
$(this).addClass('active')
.siblings('input').prop('checked',true)
.siblings('.img-radio').css('opacity','1');
});
});
The selected have the active class !, so after the post back, save the user selection and render the selected control with that class.
I am using a asp.net FileUpload control to upload files. There is a 'Title' text box which allows user to enter file title as well. The 'Upload' button then uploads the file to the server. This is all working fine. My problem however is that, customer has asked to copy the file name automatically to the title 'text box' in case user wants the custom title to be the same as file name.
Unfortunately, I am unable to figure this one out. I thought there would be an event behind the 'open' button of the file upload, that I could tap into and just as the title gets displayed on the fileupload control, similarly it should also get displayed on my title text box field. Perhaps Javascript/JQuery might help.
Any help in the right direction would be greatly appreciated. Many thanks
You can use the input's change event with jQuery:
$(function () {
$('input:file').on('change', function () {
console.log($(this).val());
})
})
You will probably have to parse the value to remove the "fakepath" stuff that some browsers add.
You can do this using the split method:
var title = $(this).val().split('\\');
console.log(title[title.length - 1])
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.
I have an asp.net web page (C# 2008) where the user would enter an EmployeeID, and when they tab out of the textbox (the page executes a validation code block in the codebehind), they get a messagebox prompting them to select one of two values from a dropdown listbox.
The code for the message prompt in the codebehind is :
Response.Write("<script>window.alert('Please select Alpha or Beta')</script>");
After the prompt is displayed, and the user clicks "ok" and returns to the page, the text on the page appears distorted (the text in labels are a size larger, the labels get wrapped to another line etc)
I tried putting a Response.Redirect("UserProfileMaint.aspx"); after the messagebox in the codebehind, but now, the messagebox does not appear;
So this is my squence:
User enters EmployeeID
If user has NOT selected Alpha or
Beta, then show messagebox
If user HAS selected Alpha or Beta,
then don't show messagebox
I want to display the messagebox validation, and ensure the appearance of the text on the page is not distorted. How can I do this?
Response.Write writes directly to the output stream, placing it before <html> which the browser gets very confused by (causing your text issues). What you want to do instead is this:
ClientScript.RegisterStartupScript(GetType(), "alert",
"alert('Please select Alpha or Beta');", true);
ClientScript.RegisterStartupScript includes the script in the page to be run on load rather than put in the response too early. The last argument: true is telling it to wrap that alert in <script> tags, keeping your code-behind cleaner.
The best way to handle this would be to use Javascript and do Client side validation. If you really want to do server side validation then instead of showing a alert by using Response.Write you should use RegisterStartupScript or better show the message using a Label at the top.
HTH
When you call Response.Redirect, that occurs on the server side, whereas you want the redirect to occur on the client side after a choice is made.
To do that, when you write your script with Response.Write (btw, there are much better ways to do this), you would have logic that determined what the user selected, and then based on the selection, either requery them for data, or set the location property of the inherent document object to the url you want to redirect to.
Ok so while back I asked question Beginner ASP.net question handling url link
I wanted to handle case like this www.blah.com/blah.aspx?day=12&flow=true
I got my answer string r_flag = Request.QueryString["day"];
Then what I did is placed a code in Page_Load()
that basically takes these parameters and if they are not NULL, meaning that they were part of URL.
I filter results based on these parameters.
It works GREAT, happy times.... Except it does not work anymore once you try to go to the link using some other filter.
I have drop down box that allows you to select filters.
I have a button that once clicked should update these selections.
The problem is that Page_Load is called prior to Button_Clicked function and therefore I stay on the same page.
Any ideas how to handle this case.
Once again in case above was confusing.
So I can control behavior of my website by using URL, which I parse in Page_Load()
and using controls that are on the page.
If there is no query in URL it works great (controls) if there is it overrides controls.
Essentially I am trying to find a way how to ignore parsing of url when requests comes from clicking Generate button on the page.
Maybe you can put your querystring parsing code into IsPostBack control if Generate button is the control that only postbacks at your page.
if (!IsPostBack)
{
string r_flag = Request.QueryString["day"];
}
As an alternative way, at client side you can set a hidden field whenever user clicks the Generate button, then you can get it's value to determine if the user clicked the Generate button and then put your logic there.