How to set the current tab/content on page postback - c#

I have the following JSFiddle which changes the tab/content based on user selection: http://jsfiddle.net/sikni8/3d64w6gf/1/
HTML snippet sample:
<asp:Button ID="btnRegister" ClientIDMode="Static" runat="server" Text="Register" OnClick="btnRegister_Click" />
<!--<input type="submit" name="commit" value="Register" runat="server" />-->
The btnRegister button perform some action when clicked. When the page does a postback, how can I ensure the tab/content which was there is displayed.
For example, if I click on the Register button the page refreshes and brings the first tab/content to view. I would like to change it so that when Register button is clicked and the page reloads, it should remain with the same tab/content.
I can use sessionStorage but I would like to request some assistance.
Tried this but didn't work:
<script>
$(document).ready(function (e) {
localStorage.setItem("whichTab", $("#tabs nav ul li.tab-current"));
alert(localStorage.getItem("whichTab"));
});
</script>
I am using cbpFWTabs.js file to achieve the tab class switch which is in the fiddle.

I did something similar by using hidden field, where I stored the id/class of the current tab in hidden field and after postback I just displayed the current tab again.

Related

Submit Event Not Firing on Control

I have a webpage with a control to handle all the comments so I don't have to copy the code from one page to another. When I click the button, the code to handle the submit is not happening. I want the page to have no .axd references.
This is my form statement on the .aspx page
<form id="formAlpha" method="post" runat="server" action="">
<Comm:Comm ID="comments" runat="server" />
</form>
The processing for saving the comments is in the control.aspx
In the code of the webpage, I set the action to be
formAlpha.Action = Request.RawUrl;
This is my submit button in the control.
<asp:button ID="cmdSubmit" CausesValidation="false" UseSubmitBehavior="true" text="Submit" runat="server" OnClick="cmdSubmit_Click" OnClientClick="return ValidateSubmission();" />
The JS code executes correctly, it displays an alert box and then returns true. THe page reloads but the click event doesn't work. The load event fires up again and the IsPostBack is false. Its not submitting but reloading.
I'm using WebForms C#, not MVC
Just an idea taken from the official MSDN page, remove the "return" (and maybe the semicolon too) keyword from the onClientClick declaration:
OnClientClick="ValidateSubmission()"

asp:button with no post back or refreshing the page

I have button in my page that when click on fires a jquery method that shows a div, but if the browser doesn't support javascript I want to fire a code behind method (using a postback). Is this possible? I'm already using this code but i can't see any results:
<asp:Button ID="Button1" runat="server" Text="Upload Files Here" Width="187px" onClick="CodeBehindMethod" OnClientClick="show_upload_box();return false"/>
and this is my jquery code:
function show_upload_box() {
$("#pop_up_background").css({
"opacity": "0.4"
});
$("#pop_up_background").fadeIn("slow");
$("#signup_pop_up_box").fadeIn('slow');
window.scroll(0, 0);
}
If the browser doesn't support JavaScript then your button would not work.
In ASP.NET, the runat="server" instruction is actually tied to a JavaScript method that submits a form (view page source to see that method).
Change or remove the value of that property to prevent the post back to your server.

Send HTML Parameter to button click event in ASCX child control

I'm trying to access some page HTML to use for an email in a Button_Click event.
I cannot set this content easily anywhere else at runtime (Such as in a TAG).
So I'm wondering if I can use JQuery to set a variable to .innerHtml(), and pass that in the button click. How would I go about doing this?
Something like this...
<div id="myDiv">
some content...
</div>
<asp:HiddenField ID="hdnHtml" ClientIDMode="Static" runat="server" />
<script type="text/javascript">
$(function () {
$('#hdnHtml').val($('#myDiv').html());
});
</script>
To add a hidden field to a form: fill its value using javascript/jQuery and submit the form via a Button_Click event.

Store innerhtml by jQuery in asp.net?

I have
<div id="ulAndil" runat="server">
</div>
and button
<asp:Button ID="btnAssignJudToCourse" runat="server" Text="تاكيد "
CssClass="button" CausesValidation="false"
OnClientClick="javascript:getShape();"
OnClick="btnAssignJudToCourse_Click" Visible="false" />
At runtime I create a lot of sortable html controls and then click confirm
I want to save inner html of this div before postback of button in session or anything
Using jQuery so when user click the button jQuery take inner html of div and stores it in cookie session any thing to store it after postback I can retrieve it
Please I want the exact code for this jQuery or javascript method and how to call on button
Why don't you put the generated HTML in a hidden field and postback.
Say getShape() is your javascript function
function getShape()
{
//your validations applied
document.getElementById('hdnHTML').value = document.getElementById('ulAndil').value;
return true;
}
where hdnHTML is the hidden element of HTML.

Inserting text in TextBox at cursor

I have a textbox in aspx page in which the user enters text. Now when user clicks on a button called "Sin" the textbox should show "Sin[]" and the cursor has to be placed in between brackets.Like as follows "Sin[<cursor here>]" Now when the user clicks on some other button say "Cos" the textbox text should show "Sin[Cos[]]" and the cursor has be placed between the brackets of Cos as follows: "Sin[Cos[<cursor here>]]".
How is this handled. Any simple code please..
Thanks in advance
I hope you are using jquery.
<asp:TextBox id="txt" runat="server" />
<input type="button" id="sinBtn" value="Sin" tag="Sin[<cursor here>]" />
<input type="button" id="cosBtn" value="Cos" tag="Cos[<cursor here>]" />
//also you can generate the two buttons with server controls
Here is the javascript:
$(document).ready(function(){
$('input[tag]').click(function(){
var theText = $('#<%= txt.ClientID %>');
theText.txt(theText.txt().replace('<cursor here>',this.tag);
})
});
If you don't have a string.replace method, extend one using prototype.
I think this shouldnt be difficult with jQuery.
Look at these links:
jQuery Tutorial
inserting-a-text-where-cursor-is-using-javascript-jquery
10-jquery-and-non-jquery-javascript-rich-text-editors

Categories