ASP.NET Wizard Steps: Getting form data to next page? - asp.net

I can't figure out how to pass form data from a Wizard Steps Control to a new page. I posted THIS POST some days ago, but the answer here didn't really help me because i can't even get the value from a TextBox on the new page.
I put tried to put this insted of the hiddenfield but <asp:TextBox ID="amount" runat="server" Text="tester"></asp:TextBox> but the Request.Form["amount"] is still just null.
How do i pass form data from a wizard steps control to a new page? Should this really be that hard?

For information that we collect in a wizard usually translates into a business object, then we just pass that object around in a Session variable. That way we have access to it on any page.

Session variable seems to be easier to work with:
Default.aspx markup:
<asp:Wizard runat="server" ID="wizAwesome" FinishDestinationPageUrl="~/TestPage.aspx" OnFinishButtonClick="wizAwesome_FinishButtonClick">
<WizardSteps>
<asp:WizardStep ID="stepRock" runat="server" Title="Rock!">
This is a wizard step.
<asp:HiddenField runat="server" ID="hiddenName" Value="Juliet" />
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
Default.aspx.cs
protected void wizAwesome_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
Session["hiddenName"] = hiddenName.Value;
}
TestPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = Session["hiddenName"].ToString();
}

Your HiddenField needs to be located outside of the Wizard like below and you need to add a FinishNavigationTemplate which posts the data to your new page
<asp:Wizard runat="server" ID="wzd_Amount">
<WizardSteps>
<asp:WizardStep ID="step_Amount" runat="server">
This is a wizard step.
</asp:WizardStep>
</WizardSteps>
<FinishNavigationTemplate>
<asp:Button runat="server" ID="btn_Finish" PostBackUrl="~/Labs/TestPage.aspx" />
</FinishNavigationTemplate>
</asp:Wizard>
<asp:HiddenField runat="server" ID="hdf_Amount" Value="Test" />
On the other page you can just Request the data like so
lbl_Test.Text = Request["hdf_Amount"];

Related

Load another web page based on value of drop down list in asp.net

I am trying to redirect to another web page when the user selects the drop down list and the user should be redirected to another web page as soon as the user clicks the submit button.This is my code for drop down list and button.On clicking the "click to proceed" button the user should be taken to next web page depending on list selection.
Iam new to .Net Please help thanks in advance !!
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="-1">Select User</asp:ListItem>
<asp:ListItem Value="staff">Staff</asp:ListItem>
<asp:ListItem Value="student">Student</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Click to Proceed" />
In your Button1_Click event, use the Response.Redirect method to send people to the appropriate page.
http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.110%29.aspx
Following can be helpful for you.
protected void Button1_Click(object sender, EventArgs e)
{
string sel_val = DropDownList1.SelectedValue; // use sel_val to apply if, else logic to redirect to
// some possible examples
if (sel_val != "-1") // as SelectedValue is string
{
// assuming there is staff.aspx, and you want to redirect to that page on selecting staff, this is just an example
Response.Redirect(sel_val + ".aspx"); // use this to redirect to required page
}
}
Also change aspx code like this.Note i have changed OnClick from onclick.
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Click to Proceed" />

Unable to call a button for asp.net website

So the problem here is that i am unable to call a button that another developer created and handed over the site to me.
He is not available and I am not very much into ASP.net but really need to figure this out.
The code is:
<div class="clearfix">
<asp:UpdatePanel runat="server" id="UpdatePanel2">
<ContentTemplate>
<asp:Label ID="lblDesc" runat="server" Text=""/>
<asp:LinkButton ID="btnMore" runat="server" Text="more"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
The btnMore should call a button at server making the word more to be a link that will expand the div to get a blog post from the database.
It is not doing so.
Any idea why??
Your LinkButton has no associated action with it. You need to set the OnClick attribute to the function on the server side that has the correct signature. For example...
<asp:LinkButton ID="btnMore" runat="server" Text="more" OnClick="btnMore_Click" />
Then in your code behind...
protected void btnMore_Click(object sender, EventArgs e)
{
//do your server side stuff
}

how to make a validation code for ASP.NET form with VB coding

im trying to build a form+attachment that needs to be send to email.
Im using a VB background code (attachementemail.aspx.vb)
and my front (b-16.aspx)
I want the page to check that the user entered a email, name, phonenumber and attachment.
what command do I put in the axp.vb
and what on the .aspx
tried just about anything.
The simplest way is to use validators eg RequiredFieldValidator for mandatory fields. You can also implement CustomValidators for custom logic.
See http://msdn.microsoft.com/en-us/e5a8xz39.aspx for the available validators
At it's basic level you could use RequiredFieldValidator and CustomValidation in your form. You can use some regex logic for email, I use this but there are many out there:
Regex(#"\w+([-+.]\w+)#\w+([-.]\w+).\w+([-.]\w+)*")
Personally I use client side javascript before it hits the server and then I re-validate the entries once it hits the server. If your using the postback events then you'll need update panels and a scriptmanager (not sure if you are aware of this already, so apologies if teaching you to suck eggs!).
Here is an example:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Code behind (sorry this is in c#)
protected void Button1_Click(object sender, EventArgs e)
{
if (RequiredFieldValidator1.IsValid)
{
Label1.Text = "Has content";
}
else
{
Label1.Text = "Not valid";
}
}
Note that the required field validator has it's own methods to display a "hey you haven't entered content here my friend" message, but i have added that to the label instead.

asp.net set textbox control in panel contol

I want to set the textbox contol located in the panel control via code
I know to retrieve the inputted value in the textbox control:
string myVal = Request.Form["txtResult"];
I want to set the txtResult.text = "some text";
makeup snippet:
<asp:Panel ID="Panel1" runat="server" Style="display: none" Width="233px">
<asp:TextBox ID="txtResult" runat="server" AutoPostBack="True"></asp:TextBox>
<br />
<div align="center">
<asp:Button ID="OkButton" runat="server" Text="OK" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</div>
</asp:Panel>
txtResult is not available within code, I tried to see if it is available in the page_load, it's not
texReults was a typo, its txtResult, I updated the ID
the intellisense does not recognize any cntr by the name txtResult
its a new web application and the panel visibility=True
maybee this wil help, above the snipet, I use ScriptManager from the AJAX Exstension
I am aware of he Asnchronius affects, partial potback, etc.
It's a managed control, you should be able to set it on the Page_Load event:
protected void Page_Load(object sender, System.EventArgs e)
{
txtResult.Text = "some text";
}
Update: Based on your update, there are a couple of things that you would need to check:
Spelling: Are you sure you're spelling the control name correctly?
Its ID in your code is "txtResults", but you're referencing it as
"txtResult".
Designer: Did you copy the aspx page or bypass VS in some way for this page? If so check the .designer file for the reference to the control: i.e. "Page1.aspx.designer.cs"
Visibility: Is the Panel control's visibility set to true? If not, then it won't render the controls that are contained within it.
Update 2: If you're doing this through scriptmanager, then I highly recommend that you read through this: http://www.wrox.com/WileyCDA/Section/Using-the-ASP-NET-AJAX-ScriptManager.id-305492.html

Embedding multiple user controls into a page?

I've embedded multiple user controls into the same page. The user controls typically have 2 different views, an edit/default view and a completed view. When the user completes an edit then I switch the MultiView to the completed state. This pattern works okay in pages.
The problem is when I go back to the master view/page then the user brings back the control, the view is still in the completed state.
What are some simple methods for resetting/correcting the multiview state? I could have a Reset() function on every control but it feels like I may be able to avoid that.
Update:
This page is designed to show an account/profile view and it has the following parts:
<asp:MultiView>
...read only view
<asp:EmailEditView>
<asp:AccountEditView>
etc..
And then each of those views has a user control. Inside the user control, we have something like this
<asp:multiview>
<asp:view id="edit"/>
<asp:view id="completed"/>
I've found the following problems with this design:
When the user completes an action of user control such as changing an email. The view stays in the finished state even when they go back to it a second time.
When the user goes back to the original form the data is stale. This design really screws with the postback mechanism. If I don't use !IsPostBack on the main form for databding then my dropdownlist on the sub forms will not work. However, once I add the !isPostBack on the main form then the data becomes stale.
I can add a "reset" flag to every user control and add something like this
if ((!IsPostback) || (reset) )
As well as resetting the view. In the other scenario, I can add an event handler to load the reload/bind the data when the user clicks "back", i.e where I change the form back.
I'm trying to recreate the functionality of your problem while taking out the complexity of user controls. Here's my best guess so far (please correct me if I'm wrong)
<asp:MultiView runat="server" ID="MainMultiView" ActiveViewIndex="0">
<asp:View runat="server" ID="DefaultView">
Default View
<asp:Button runat="server" ID="EditEmailButton" Text="Edit Email" OnClick="EditEmailButton_Click" />
<asp:Button runat="server" ID="EditAccountButton" Text="Edit Account" OnClick="EditAccountButton_Click" />
</asp:View>
<asp:View runat="server" ID="EmailView">
<asp:MultiView runat="server" ID="EmailMultiView" ActiveViewIndex="0">
<asp:View runat="server" ID="EmailEditView">
Edit Email
<asp:Button runat="server" ID="SaveEmailButton" Text="Save"
onclick="SaveEmailButton_Click" />
<asp:Button runat="server" ID="CancelEmailButton" Text="Cancel"
onclick="CancelEmailButton_Click" />
</asp:View>
<asp:View runat="server" ID="EmailCompleteView">
Email Edit Complete!
</asp:View>
</asp:MultiView>
</asp:View>
<asp:View runat="server" ID="AccountView">
<asp:MultiView runat="server" ID="AccountMultiView" ActiveViewIndex="0">
<asp:View runat="server" ID="AccountEditView">
Edit Account
<asp:Button runat="server" ID="SaveAccountButton" Text="Save"
onclick="SaveAccountButton_Click" />
<asp:Button runat="server" ID="CancelAccountButton" Text="Cancel"
onclick="CancelAccountButton_Click" />
</asp:View>
<asp:View runat="server" ID="AccountCompleteView">
Account Edit Complete!
</asp:View>
</asp:MultiView>
</asp:View>
</asp:MultiView>
-- code behind
protected void EditEmailButton_Click(object sender, EventArgs e)
{
MainMultiView.SetActiveView(EmailView);
}
protected void EditAccountButton_Click(object sender, EventArgs e)
{
MainMultiView.SetActiveView(AccountView);
}
protected void SaveEmailButton_Click(object sender, EventArgs e)
{
// Save();
EmailMultiView.SetActiveView(EmailCompleteView);
}
protected void CancelEmailButton_Click(object sender, EventArgs e)
{
EmailMultiView.SetActiveView(EmailCompleteView);
}
protected void SaveAccountButton_Click(object sender, EventArgs e)
{
// Save();
AccountMultiView.SetActiveView(AccountCompleteView);
}
protected void CancelAccountButton_Click(object sender, EventArgs e)
{
AccountMultiView.SetActiveView(AccountCompleteView);
}

Resources