Making a form on asp.net - asp.net

I'm having a problem making a button which would actually copy the information of the form and then displaying that information right below it! Please help me out in this.
I'm doing this in ASP.NET and trying to do in web forms!
Also the IDE I'm using is visual studio 2015

in asp.net if you want server side copy the information
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button ID="Button1" Text="show" runat="server" OnClick="Button1_Click" />
<asp:Label Text="result" ID="Lable1" runat="server" />
in behind
protected void Button1_Click(object sender, EventArgs e)
{
Lable1.Text = TextBox1.Text;
}

Related

Asp.net C# - checkbox control won't stay true after code-behind runs

Front HTML
<asp:CheckBox ID="chkSend" runat="server" Text="Send?" />
The code that triggers the code behind
<asp:DropDownList ID="ddlStatus" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged" AutoPostBack="true"
runat="server" DataValueField="Id" DataTextField="Status" />
The code that runs in the code behind
protected void ddlStatus_SelectedIndexChanged(object s, EventArgs e)
{
this.chkSend.Checked = True;
}
When get back to the front end , the checkbox isn't checked. Any Ideas?
If it helps, this particular view is using Multi-views to which I'm new to.

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
}

ASP.NET GridView Image Command Button Problem (Multiple PostBacks)

ASP.NET GridView Image Command Button causes Multiple PostBacks.Is this is a known issue ? or is there any solution(not workaround).
Try using this way
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="Button" runat="server" ImageUrl="../images/Editicon.png" OnClick="Button_Click" />
</ItemTemplate>
</asp:TemplateField>
protected void Button_Click(object sender, EventArgs e)
{}
I m sure you wont face ne problem with this

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

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

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"];

Resources