Multiview refreshes page and losing data in ASP.NET Webform - c#

I have problem with Multiview in ASP.NET webform. I am building a form, where on the same page a user should upload his avatar in the first form and on the second form user should enter profile info and upload a document. The problem is when I switch between the forms in Multiview, it refreshes my pages and I lose all my data. For example if user uploads his avatar and goes to the profile to enter info, and suddenly decides that he wants to change his avatar and switches back to the username tab, his already uploaded avatar is lost. I have tried to solve it with jQuery tabs, but I did not have the wanted result. Also I have tried to add an Update Panel to the Multiview and Script Manager, also id did not work for me. If anybody has a clue how to solve this, I would be very grateful!
Here is Designer.cs
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="ViewForm1" runat="server">
<div class="multiviewButtons">
<asp:Button ID="Button1" runat="server" Text="Username" OnClick="Button1_Click"/>
<asp:Button ID="Button2" runat="server" Text="Profile" OnClick="Button2_Click"/>
</div>
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true" placeholder="Enter your username"></asp:TextBox>
<asp:Label ID="Avatar" runat="server" Text="Insert Avatar"></asp:Label>
<asp:FileUpload ID="uploadAvatar" runat="server"/>
</asp:View>
<asp:View ID="ViewForm2" runat="server">
<div class="multiviewButtons">
<asp:Button ID="Button3" runat="server" Text="Username" OnClick="Button1_Click"/>
<asp:Button ID="Button4" runat="server" Text="Profile" OnClick="Button2_Click"/>
</div>
<asp:TextBox ID="txtProfile" runat="server" AutoPostBack="true" placeholder="Enter your profile info" TextMode="Multiline"></asp:TextBox>
<asp:Label ID="Profile" runat="server" Text="Insert your pdf document"></asp:Label>
<asp:FileUpload ID="uploadDocument" runat="server"/>
</asp:View>
</asp:MultiView>
And in my CodeBehind.cs file
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0;
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 1;
}

Actually, this is one of those cases in which is better to roll your own!!
And it turns out in most cases its less work.
So, move the two buttons outside of the two "panels".
And in fact, lets dump the whole multi-view, and use simple markup.
In this case, it turns out its probably less work.
So, this markup:
<asp:Button ID="Button1" runat="server" Text="Username" CssClass="btn"
OnClientClick="myshow(1);return false;"/>
<asp:Button ID="Button2" runat="server"
Text="Profile" CssClass="btn"
Style="margin-left:15px"
OnClientClick="myshow(2);return false"/>
<script>
function myshow(iMyShow) {
if (iMyShow == 1) {
$('#View1').show()
$('#View2').hide()
}
if (iMyShow == 2) {
$('#View1').hide()
$('#View2').show()
}
}
</script>
<br />
<br />
<div id="View1" style="display:normal">
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true" placeholder="Enter your username"></asp:TextBox>
<asp:Label ID="Avatar" runat="server" Text="Insert Avatar"></asp:Label>
<asp:FileUpload ID="uploadAvatar" runat="server"/>
</div>
<div id="View2" style="display:none">
<asp:TextBox ID="txtProfile" runat="server" AutoPostBack="true" placeholder="Enter your profile info" TextMode="Multiline"></asp:TextBox>
<asp:Label ID="Profile2" runat="server" Text="Insert your pdf document"></asp:Label>
<asp:FileUpload ID="uploadDocument" runat="server"/>
</div>
<br />
<asp:Button ID="cmdDone" runat="server" Text="Submit" CssClas="btn" />
So, two REALLY simple divs, and two simple buttons. they have NO server side code.
So, you now get this:
Since we hide/show the div with some simple js code (jQuery), then the above has no post-back and is really simple.
I fact, a nice touch I used for years?
Well, when you click on one of the two buttons to select/show the simple "div"?
You often can't tell which "fake tab" we are on.
So, in place of the two buttons?
Drop in a Radio Button list. Once again, we don't need a post-back, but REALLY nice is a radio button list SHOWS which button is selected!!!
So, drop in radio button list, enter the two button text values (all wizards). Set the layout to be horizonal (not vertical).
So, now we have this:
(edit/add items with wizard, and enter your two "fake" tab control names
So, we now have this:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" CssClass="rMyChoice">
<asp:ListItem onclick="myshow(1)" Value="1" Selected="True">UserName</asp:ListItem>
<asp:ListItem onclick="myshow(2)" Value="2">Profile</asp:ListItem>
</asp:RadioButtonList>
Now, I SHOULD be able to add the onclick event to the rb list, but a rendering issue causes the rb to trigger 2 times, so, we have to add the onclick (this is client side) to each selection.
With the above, then the Radio button shows which selected - which is rather nice for the user.
eg this:
Like anything, the default rblist and even spacing looks "horrible".
but, we can style the rb list. So, say this:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" CssClass="rMyChoice" >
<asp:ListItem onclick="myshow(1)" Value="1" Selected="True">UserName</asp:ListItem>
<asp:ListItem onclick="myshow(2)" Value="2">Profile</asp:ListItem>
</asp:RadioButtonList>
So, now we get this:
So, a few simple divs tend to be less work. you can as noted drop in two buttons.
So a rb list is nice since it shows/gives feedback as to which option in the rb list is selected. Toss in a style sheet (which even with your original buttons etc. you probably required)?
Then all in all, I think we wound up with LESS markup, no server post-back, and in fact I use the above trick for MOST of my pages - (very much like a menu in a given page). So, this works if you have 3 or 5 choices.
As for that style sheet for the rb list. Have to dig it up and open it!!! - not looked at it for years.
Oooo - more then expected, but the css file was this:
.rMyChoice h1 {
color: hsla(215, 5%, 10%, 1);
margin-bottom: 2rem;
}
.rMyChoice section {
display: flex;
flex-flow: row wrap;
}
section > div {
flex: 1;
padding: 0.5rem;
}
.rMyChoice input[type=radio], input[type=checkbox] {
display: none;
cursor: pointer;
}
.rMyChoice label {
display: block;
background: white;
border: 2px solid hsla(150, 5%, 75%, 1);
border-radius: 25px;
padding-left: 8px;
padding-right: 8px;
text-align: center;
box-shadow: 0px 3px 10px -2px hsla(150, 5%, 65%, 0.5);
position: relative;
margin-right: 9px;
}
.rMyChoice input[type="radio"]:checked + label, input[type="checkbox"]:checked + label {
background: hsla(150, 5%, 75%, 1);
color: hsla(215, 0%, 100%, 1);
box-shadow: 0px 0px 20px hsla(150,5%, 75%, 0.75);
}
.rMyChoice input[type="radio"]#control_05:checked + label {
background: red;
border-color: red;
}
.rMyChoice p {
font-weight: 900;
}

Related

How to set anchor for label in web form application in code? c#

I wanted to set anchor for label but in properties of label i could not find anchor field and how can set it by code maybe in style?
I tried to write in page_load label.Anchor but it cant find this class.
.labelName{float: left; text-align: center; margin-left: 810px ; margin-top: 20px;width: 150px; }
</style>
<div class="labelName">
<asp:Label ID="lblGameName" runat="server" Text="Huina Game"> </asp:Label>
</div>
You should use asp:HyperLink that render as anchor or asp:LinkButton if you need to do a postback with server side handler
<asp:HyperLink ID="labelWithLink" runat="server" NavigateUrl="https://stackoverflow.com" Target="_blank"></asp:HyperLink>
<asp:LinkButton ID="labelWithLinkAndPostback" runat="server" OnClick="ServerSideHandler_click" ></asp:LinkButton>

Response.Redirect need to click twice

I have a input text box and the button when the button is pressed whatever is in the textbox should be appended as a querystring and be redirected to another url. However I need to click the button twice before the redirect happens.
This is the aspx code
<div class="userInputTextBox" style="margin-left: auto; margin-right: auto; margin-top: 10px;">
<asp:TextBox
placeholder="Enter costumer ID"
ID="TextBoxID1"
runat="server"
AutoPostBack="true"
Columns="80"
Visible="true">
</asp:TextBox>
<asp:Button runat="server" Text="Search" OnClick="Search" />
</div>
Code behind with the Search method.
protected void Search(object sender, EventArgs e)
{
Response.Redirect(String.Format("UserDetail.aspx?UserID={0}", Server.HtmlEncode(TextBoxID1.Text)));
}
Ok I figured that I only needed to delete the AutoPostBack="true" property and it works ok now

Required field validator text positioning

I have problem getting my text from the validation under my textbox. It show up behind my textbox, just like in picture.
In my code for the type of assignment and assignment start textbox i have a css-class setting saying that display = block. That put the validation text under the textbox. If i put that on this element my second textbox end up under the first one (for example, the big empty textbox after the textbox saying AC- end up under the textbox saying AC-). I tried all different solutions but maybe I'm staring myself blind on the problem. I will pust my current code and i hope anyone out there can help me fix this problem.
first my aspx...
<div class="floatLeftPaddTop15PaddLeft40">
<asp:Label id="costCodesLabel2" runat="server" >Cost code 2:</asp:Label><br />
<asp:TextBox id="costCodeTextBox2Prefix" runat="server" CssClass="textBoxPrefix" Visible="false" ></asp:TextBox>
<div class="costCodeDiv" >
<asp:TextBox id="costCodeTextBox2" runat="server" CssClass="textBoxSuffix" ></asp:TextBox>
<asp:RequiredFieldValidator ID="costCodeValidator2" runat="server" ControlToValidate="costCodeTextBox2" ErrorMessage="Cost code is required."
ForeColor="Red" Display="Dynamic" Enabled="false" />
</div>
</div>
then my css...
.textBoxSuffix {
width: 120px;
height: 22px;
border: 1px solid #999;
}.
.textBoxPrefix {
width: 35px;
height: 22px;
border: 1px solid #999;
}
Or you can build the page with a html table ...

How to show result of an event in loading panel in asp.net

I am working on asp.net and ajax using c#. I am trying to create a new user registration where i am poping a updatepanel with loading image when an user clicks on submit button. and also i need to insert the data into database at the same time. I use the following code,
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtMI" Width="80px" Height="20px" CssClass="s1"> </asp:TextBox>
<asp:TextBox runat="server" ID="txtMI" Width="80px" Height="20px" CssClass="s1"></asp:TextBox>
<asp:TextBox runat="server" ID="txtMI" Width="80px" Height="20px" CssClass="s1"></asp:TextBox>
<asp:Dropdownlist ID="drpCountries" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Dropdownlist>
<br />
<asp:Button ID="btnLoad" runat="server" onclick="btnLoad_Click" Text="submit" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress id="updateProgress" runat="server">
<ProgressTemplate>
<div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/avatarloading.gif" AlternateText="Loading ..." ToolTip="Loading ..." style="padding: 10px;position:fixed;top:25%;left:35%;" /><center><span style="color:White;font-weight:bolder;font-size:x-large;"><b>Loading...</b></span></center>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
and in my code behind file like,
protected void btnLoad_Click(object sender,EventArgs e)
{
//INsert the records into database
}
At first when user clicks on submit i am able to pop loading panel with loading gif image. after successful insertion i need to show some message like registration success in place of image on loading panel. please guide me.
You can bind endRequest event of asp.net ajax to get control after ajax request completed.
<script language="javascript" type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(endRequest);
function endRequest(sender, args) {
alert("After ajax request");
}
</script>
I'd create a panel which looks identical to the UpdateProgress markup (css classes) with a label in it. And on a successful operation you set the label text and switch the panels Visible property to true.

Issues with IE6 panels in asp.net application?

I ran into the alignment issues with IE6.Code works just fine with IE8.I have no other option but to support IE6.
Description:
My web page contains two pages.
Issue with page1(IE6):
I have two panels in the page1 which carry a grid view each.I want to place the panels with some grouping text in the page .As the grid view data keeps growing i want to keep the both panels aligned horizontally one at left side of the page and one at right side of the page.So it works exactly in IE8 but when i switch to IE6 the panels are aligning themselves vertically on above the other.
Here is the code
<div>
<div style="float: left">
<table width="100%">
<tr>
<td>
<asp:Panel ID="pnlUsers" runat="server" GroupingText="UserDetails "Wrap="true">
</asp:Panel>
</td>
</tr>
</table>
</div>
<div style="float: right">
<table align="center" width="100%">
<tr>
<td>
<asp:Panel ID="pnlLocation" runat="server" GroupingText="Location Details" Wrap="true">
</asp:Panel>
</td>
</tr>
</table>
</div>
</div>
Issue with Page2(IE6)
So in this page the max height of the panel is not taken and its extends vertically irrespective of the max height set to the panel!!!
<asp:Panel ID="pnlAge" runat="server" ScrollBars="Vertical" Width="100%"
HorizontalAlign="Center" CssClass="pnlAlignmentClass">
<asp:GridView runat="server" ID="gvages" AutoGenerateColumns="False" CellPadding="4" Width="100%">
</asp:GridView>
</asp:Panel>
CSS:
.pnlAlignmentClass
{
max-height: 310px;
overflow: auto;
}
I would appreciate if some one can suggest the right path .
IE6 does not support max-height. You can use regular height, but in IE6 it actually behaves like min-height.
To do max-height in ie6, follow this link: http://perishablepress.com/press/2007/01/16/maximum-and-minimum-height-and-width-in-internet-explorer/
* html div#division {
height: expression( this.scrollHeight > 332 ? "333px" : "auto" ); /* sets max-height for IE */
}
div#division {
max-height: 333px; /* sets max-height value for all standards-compliant browsers */
}

Categories