Calling server side function from client side - c#

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>

Related

update status text without page reload

I have a web app! I set a status text for users that is shown below the profile picture of the user. Whenever the user updates the status text, the page reloads on button click, and then the new status appears below the picture. Is there a way to prevent this page reloading and still make the status text changed?
On submit, the new status text is inserted/updated into the database table and then on page load, it is fetched.
You can use Ajax,
Place your Update Button and Status TextBox inside a AjaxUpdatePanel
If it's not possible to add both (Update Button and Status TextBox) to a single AjaxUpdatePanel (as your HTML design), add two different Ajax UpdatePanels (to Update Button and Status TextBox) and call yourstatusupdatepanelname.Update(); from Update Button Click event
you can use jquery ajax to do that and it is easy and will not load your page every time you click a the button:
Asp.net Jquery ajax example
you just asign the status again in button click on success execution of sql statement
I think you need to find out using about ajax , postback for this situation.
You can try with Timer_Tick Event

How to navigate to a web form programmatically

How I can navigate to a web form on button click?
I have a datagrid with user information. I want to open an asp.net web form in the same master pages content place holder, when the user clicks on a row .
Any advice?
Response.Redirect("secondpage.aspx"). This redirects to that page. Save the row number, id, etc. in the session state like Session["rowid"] = 1 or send it as a querystring like secondpage.aspx?rowid=23. You need to save the row information and get that rowid from the second page and load the information for that row.
whithin the button tag : PostBackUrl="~/TargetPage.aspx"

onclick of any link the web user control is loaded without post back

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();
});

Modalpopup not working properly asp.net ajax

I have an updatepanel,a modal popup extender inside that and an image button to open the pop up(it has not any click event). The 'div' for the modal pop up is outside the updatepanel. In the modal pop up the records come in a table with a link in each table row.When the link is clicked,a javascript function causes a hidden control to postback and fetch values from database.First time it is working fine,but next time the image button(TargetControlID for modal pop up extender) does not work and it is causing a postback and loading the page.Help plz...
Thanks in advance.
Mohak
Are you using myLink.ClientID or did you hardcoded the ID of the link in the Javascript function?
The ID of the link is probably changed when doing the first postback, the second time ASP.NET has generated a new ID (not visible in the HTML because of the AJAX-request) for your link and this doesn't match anymore with the ID in your Javascript function.
The solution would be to use myLink.ClientID

Possible to run a javascript function after postback using an asp.net button?

I am trying to implement a web page that will on an asp.net submit button click will go to the server to add a row to the SQL database table. After that, on that same page, I want to be able to display the columnID as an alert using javascript (this has to be javascript). Is this possible? Any help would be appreciated.
Another trick picked up from Telerik was to create a asp:Label and place it at the top of the page. From code behind you then set the text to javascript command:
aspLabel.Text = "JavascriptFunction();";
When your page reloads, it will execute the Javascript function. It seems that in your case your just interested in displaying and alert, so registering scripts should not be necessary. In your case you can do the following:
aspLabel.Text = "alert('" + yourValue.ToString() + "');";

Categories

Resources