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.
Related
I need to add possibility to changing menus from old design to new. The changes are only the structure of the menu. I don't have any problem with that.
How I implemented the change add button, on button client click(no postback) I made one of the menu divs display:none and set hidden field to 0 or 1. On every post back I read the hidden field value and set the correct div.
My question is: Is it possible to be done without hidden field and to set the choice of the user, so when he log in again to stay with last configuration(not the default). I don't want to use postback, if it possible provide example. Thanks !
You are using JQuery so here it goes. Call the changeMenu() function in $(document).ready to make sure the old is shown first.
var current=1;//old system
//this function will be called in the button click
function changeMenu(){
if(current==0){
$("#oldMenuDiv").hide();
$("#newMenuDiv").show();
current=1;
}else{
$("#oldMenuDiv").show();
$("#newMenuDiv").hide();
current=0;
}
}
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])
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();
});
Using ajax I am causing an OnTextChangedEvent before this happens there is some Javascript that performs a check on the input field for validation and outputs some text based on whether it is valid or not. The Ajax I run resets the changes made by my javascript. It all happens in this order:
Javascript fires!
Text changes show
Ajax fires!
Text changes reset
The ajax partial autopostback is contained in an update panel. Without giving any code away is there anyone who has an idea of a way to stop the javascript changes resetting?
Over the day I will add code as I find time. Thought I would get the question up atleast. Thanks in advanced.
The Text changes are made in the DOM-Model and are not transmitted to the server.
If the ajax fires it will override the changes in the DOM made by javascript.
Solution is to transmit the validation-texts to the server and to add them again via ajax.
An UpdatePanel completely replaces the contents of the update panel on
an update.
This means that those events you subscribed to are no
longer subscribed because there are new elements in that update panel.
Full answer here
In your Page or MasterPage, put the following script
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
function EndRequestHandler(sender, args)
{
Validate(); //method that performs check on input field
}
</script>
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>