How to enter a value several times on ASP.NET Webpage? - asp.net

I have a webpage with a textbox and a button and when the button is clicked i get som calculations on the value entered, but i cannot enter another value and see calulations on that new number.
How can I achieve this? Thanks in advance.

From your question it sounds like you want to be able to change the values without having to click the button again, and have the calculations redone. The reason clicking your button works is because the page goes through a Postback The calculations are then processed server side and returned after the page has loaded. What you want to do can be accomplished in a handful of ways including: jQuery or ajax. One thing you may want to look at is jQuery .post This can help you post the values of your form to a processing page and then set the return value on your form. On the other hand since you're using .NET you could also take a look at the Microsoft AJAX Control Toolkit One place you could start is by looking at the Update Panel. Good luck and I hope this helps!

Related

Posting back to calling page from popup page

I am sure this has been asked before, but all of the links I find have to do with posting data to a popup page.
In my case I am trying to return two values/variables from the popup page back to the orginal page.
My effort thus far was to create two session variables in the popup page code behind, and then refresh the first page when the popup was closed. I'm not sure how best to do this. I do not want a fullpage refresh, I just want two textboxes to show the values of each of the session variables.
If I use the postback URL on my close button, my codebehind never fires to populate my session variables and it opens another instance of my calling page.
If someone has a link or tutorial to show this I would be very greatful.
Thank you,
Firstly I don't understand that returning value to the parent does need a session variable ?
Well you can pass the values to the parent in either json or XML or array, all you need is a piece of JavaScript which is window.parent and you can call the JavaScript method on the parent.
If your requirement is to save it in server session you can do whatever you are doing currently
I found these links which answered my question allowing me to solve this problem with ASP/VB not JavaScript, JSON or XML.
http://asp-net.wonderhowto.com/how-to/implement-cross-page-postback-asp-net-214606/
http://www.asp.net/web-forms/videos/how-do-i/how-do-i-implement-a-cross-page-postback-in-aspnet

ASP.NET dynamic controls data exchange in postback

Please excuse me for a probably low quality of this question, since I'm not a web dev, so I possibly don't now some obvious things and don't know what to Google for. I think problem must have some simple solution, but I'm struggling with it for two days now, so I feel myself pretty stupid :-).
I have a custom control which is a set of checkboxes which are added dynamically based on a property which is set in OnLoad event of a page. I have two such controls on a page and second control items should be based on items selected in first control.
The problem is, I can't figure out, how to catch on autopostback which boxes were selected in first control before second contol is constructed to pass this data to it?
Take a look at this.
http://forums.asp.net/t/1440174.aspx
Since your building them dynamically, they are not as easy to find as webforms would like to be, if you added them to the page and wired up events and such.
Your going to look at the Request.Forms list, and search thru it for any controls you want.
I believe checkboxes are like radio buttons, they only return if they are checked, which is good, cause you want to know which ones were checked.
I've used same solution as in the accepted answer for this question: Dynamically Change User Control in ASP.Net , just need to assign an unique id for each dynamically created CheckBox in custom control. Not as clean solution as I want but at least it works.
You can save the data in the ViewState, QueryString or as Session before moving to the next page and you can do modifications based on it.

Need help in asp.net viewstate

Pls somebody help me with viewsate. Suppose i have created two forms. First form contains First name and Last name and one button called NEXT. And Second form contain two fields and two button like Back and Save. While i am entering some value in form1 pressing one NEXT button and redirecting to second page. There when i am pressing Back button from second page it should come to first page whichever data i filled should exists, but in my case its not showing only empty form i can see when i am pressing on back button.
For this i have used viewstate mechanism. in page directory i have set enableviewstate=true.
postbackurl in both the button. Pls somebody help me what is wrong with me.
Thanks,
Sumit
Viewstate won't carry information from one WebForm to another. It only carries information across postbacks on the same WebForm.
You want to use another method, like SessionState, to carry information from the first page to the second page. Otherwise, you could combine all your inputs on the same page and separate them into multiple steps using something like the ASP.NET Wizard control.
David Lively's suggestions of cookie or database solutions are good, too.
ViewState will help you ship data between views/postbacks of the same page, but isn't really going to help you when moving data between separate pages.
In your first page, populate a cookie or database with your form fields. Any form can then update the cookie, delete it, or what have you.
You can call a javascript function that is doing a "real" back. Maybe I am missing something but this is what I would do.
onClick="history.go(-1)"
When a page is called from some other page it is not a post back, it is viewed as if it is a first time call... When a page is called from the same page then it is termed as a post back... View state or in the sense control values are maintained only during post back, and gets reseted to form values during first time call...
This is the reason behind why you are not seeing the values of the controls.
As others suggested, try using session or cookies and the best option would be Wizard.

Pass a value and reload User Control from Javascript

I have a User control (because I use the same in other page, so I thought I should reuse code and not double my work), but in this page I show a list of companies and each one has a company number, I need to pass this company number to that User Control and it has to reload using that passed company number.
How can I accomplish this?
what I have so far:
alt text http://www.balexandre.com/temp/2009-09-17_0917.png
the Show company structure link is made of
<a href="javascript:showStruct('112:201334607','5564967221');"
class="showStructLink">Show company structure</a>
the showStruct method is written like
function showStruct(pid, cnr) {
if (_showStrut == 0)
return;
// fancy stuff to be more apealing visually
$("#tdSearch").removeClass("tabTitleUp01").addClass("tabTitleDownUp01");
$("#tdStruct").removeClass("tabTitleDownUp02").addClass("tabTitleUp02");
$("#srtr1").hide();
$("#srtr2").hide();
$("#sttr1").show();
// enable Search Results tab to be clicked in order to get back
$("#tdSearch")
.addClass("pointer")
.bind("click", function() { hideStructure(); });
// pass the company number and reload wcCompanyStruture web user control
// __doPostBack('RefreshWebUserControl', cnr);
}
I can make a simple aspx page with the control inside and from jQuery invoke $.get() to run and populate the control correctly, but I really want to learn how to do this properly, using the ASP.NET AJAX Method to send a number and call RefreshData on it
using code-behind it is easy to refresh the user control, just invoking
wcCompanyStruture.RefreshData("companyNumberHere");
what do I need to do in my User Control side and well in the showStruct method to create this behavior?
All help is appreciated, Thank you.
I know this is not the answer to you question but I think you may be asking the wrong question.
It looks to me as if you have a search result+details view scenario that you are going about the wrong way.
When you click "Show Company structure" you want to see the details on the second tab right? If this is the case then the tab approach would be confusing to the user, it would be better with a modal popup that shows the details. No postback just AJAX load a page with the details into a modal popup window.
This is very easy with JQuery using the dialog widget in JQueryUI and the AJAX load function $('#SomeDiv').load('details.aspx?id='+companyid);
http://docs.jquery.com/Ajax/load#urldatacallback
It would give a much better user experience and it is surprisingly simple to code.
I hope this helps.
You can use a LinkButton for each "Show Company Structure" link, and set the CommandArgument property with the corresponding company id. The LinkButton will cause a postback.
A second solution would be to use a hidden variable : <input type="hidden" id="hiddenCompanyNumber"> and set it's value in the showStruct method. You can then call __doPostBack(), for which you need a control upon which to postback I think.
All in all, I think the first solution is less hacky.
You can find it here
http://codeclimber.net.nz/archive/2007/06/26/how-to-refresh-an-updatepanel-from-javascript.aspx
don't worry about the article title it has what you need Just do the four steps and you are ready to go.

Using Yes/No Messagebox in Updatepanel AJAX

I have a requirement where I ask user for confirmation and also display messages.
The programmers used for this were from Windows forms background. Hence have used the MsgBox in every nook and corner. Even in business logic part they have used the Messageboxes which requires Yes/No style confirmation from user.
When we tested the site from the remote machine we found that it gives error of using DefaultDesktopOnly/ServiceNotification. But when tested we found that this is totally different from what we were looking for.
Now my requirement is a confirmation box is shown from the code like Delete record" yes no and based on the reply we take the action.
This is to be done using updatepanel.
As you use this code in several places, I suggest you make a custom control, that takes your message and displays and Update panel with message and yes/no buttons.
Internally set some value for yes, no, cancel... so that you get something just like MessageBox.
Update panel or not, you'll have to attach some javascript that would call confirm() javascript function. Based on it's result you cancel javascript default link/button behaviour...
This will give you something to scratch your head for a start:
http://www.dotnetfunda.com/tutorials/ajax/updatepanel.aspx
That's not really a question, but a requirement.
Anyway ... MessageBox is a Windows function, it is not an HTML or browser function. Now you can mimic it in one of two ways, via a javascript confirm function or via Yes/No buttons and the appropriate event.
Given that your requirements are for something that works in an update panel I'd guess that wiring up javascript events manually for this isn't going to be something you are comfortable with, so I'd suggest an asp:Panel inside the UpdatePanel which has yes and no buttons, with server side events bound to them. In the UpdatePanel logic show this when you want confirmation and hide everything else, the act accordingly.
If you want to do server-side confirms, you'll get into more complicated code generation. First of all, you'll have two views. The first one has a link/button delete but will actually be just a postback to the second view that will display confirmation form with yes/no. In this form, your yes button will actually be your delete action...
But I'd still chose a hybrid (especially if this is a grid we're talking about) of javascript and serverside (since alert() and confirm() are evil from user experience perspective):
you have a linkbutton delete
when user clicks on it, you replace this control with a div, that displays two linkbuttons yes/no
send a postback with one of the two
Addendum
No linkbutton could be just dummy, to hide this confirmation and display delete again - so it means there won't be any server round trip
you could even create a usercontrol that mimics this sophisticated delete link behaviour to make it reusable application wide.

Resources