I'm been looking through tutorials and other questions of how to export from asp.net to word but most I've found are dealing with a simple html table which isn't what I need or involve expensive extensions.
I have a webform which users complete and submit. Once submitted I want to give them to option to export it to Word (see screenshot).
I have tried right clicking and Save As as a test to see how it comes out and it's not neat at all (see screenshot).
When I print preview the page is also a mess due to the hamburger side bar (see screenshot) are these two issues related?
Any tips on getting the word doc to look similar to the webpage?
Sample of my code:
<!--Section 4 - Health & Safety-->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseFour">Health & Safety</a>
</h3>
</div>
<div id="collapseFour" class="panel-collapse collapse in">
<div class="panel-body">
<p>Have their been any changes to Health and Safety issues since the last assessment?</p>
<label class="radio-inline">
<span class="checkableBox checkableBox-radio">
<asp:RadioButton class="validate[required]" ID="rbtnHealthYes" runat="server" value="Y" Text="Yes" GroupName="HealthAndSafetyChanges" />
</span>
</label>
<label class="radio-inline">
<span class="checkableBox checkableBox-radio">
<asp:RadioButton class="validate[required]" ID="rbtnHealthNo" runat="server" value="N" Text="No" GroupName="HealthAndSafetyChanges" />
</span>
</label>
<br /><br />
<p><i>If the answer to the above is yes, please give more details below and complete a new Health and Safety Assessment.</i></p>
<asp:TextBox class="form-control input-sm auto-size m-b-10" ID="txtHealthDetails" runat="server" TextMode="MultiLine"
placeholder="This could include things such as new renovations to the house or measures which have since broken. (This text box will grow as you fill it)"></asp:TextBox>
<hr class="whiter m-t-20" />
<br />
<br />
<p>Additional Comments:</p>
<asp:TextBox class="form-control input-sm auto-size m-b-10" ID="txtHealthComments" runat="server" TextMode="MultiLine"
placeholder="(This text box will grow as you fill it)"></asp:TextBox>
</div>
<!--Body End -->
</div>
<!--Collapse 4 End -->
</div>
<!--Section 4 End -->
http://joshcoopster.tumblr.com/image/131738484325
http://joshcoopster.tumblr.com/image/131738526900
http://joshcoopster.tumblr.com/image/131738596840
Cleanest would be to "transform" the information to a valid document type that Word can open and display. If standard HTML can give you the required quality, you can use that. If you need something more powerful you can use write WordOpenXML using the Open XML SDK.
One big question is, I suppose, whether you really need to show the form controls or whether just the information is good enough.
Related
Okay so I am trying to create a sort of registration wizard, so there are different sections within the asp such as the one below:
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="#addwizard" data-parent="#accordion-demo" data-toggle="collapse">
Term Time Address
</a>
</h4>
</div>
<div id="termaddy" class="panel-collapse collapse in" runat="server">
<div class="panel-body">
<form id="form-termaddy" >
<div class="main_input_box">
<div class="col-lg-6">
<div class="form-group">
<asp:TextBox ID="txttermhousenum" runat="server" placeholder="House Number" class="form-control" textmode="SingleLine"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator28" controltovalidate="housenum" errormessage="Required Field" display="Dynamic"/>
</div>
<div class="form-group">
<div class="main_input_box">
<asp:TextBox ID="txtxtermstreet" runat="server" placeholder="Street" class="form-control" textmode="SingleLine"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator29" controltovalidate="street" errormessage="Required Field" display="Dynamic"/>
</div>
</div>
<div class="form-group">
<div class="main_input_box">
<asp:TextBox ID="txtxtermpost" runat="server" placeholder="Postcode" class="form-control" textmode="SingleLine"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator31" controltovalidate="postcode" errormessage="Required Field" display="Dynamic"/>
</div>
</div>
</div>
</div>
</form>
</div> <!--/.panel-body -->
</div> <!-- /#addwizard -->
</div> <!-- /.panel.panel-default -->
So whenever the user fills out the form and hits save. The c# gets the details of the text boxes and updates the db:
//term time address info
string txttermhouse = ((TextBox)termaddy.FindControl("txttermhousenum")).Text;
string txttermstr = ((TextBox)termaddy.FindControl("txtxtermstreet")).Text;
string txttermpostcode = ((TextBox)termaddy.FindControl("txtxtermpost")).Text;
termaddress(txttermhouse, txttermstr, txttermpostcode);
The issue is that when the code passes through this portion it sees each of the text boxes as blank and saves them in the db as and empty string. I have also tried directly referencing the textbox into the method, ie :
termaddress(txttermhousenum.Text, txtxtermstreet.Text, txtxtermpost.Text);
But neither way seems to work. Any help on how to get the text box values would be greatly appreciated, very confused by this issue.
If you are using a master page, make sure that you do not have two <form runat="server"> tags. I've once experienced this issue and it was a result of that.
As you are using Textbox directly , no need of using of FindControl:
Try accessing them as follows
string txttermhouse = txttermhousenum.Text;
string txttermstr = txtxtermstreet.Text;
string txttermpostcode = txtxtermpost.Text;
You can pass to your method as follows:
termaddress(txttermhouse , txttermstr , txttermpostcode );
Why are you finding your controls using your div running at server? I would suggest you to remove runat="server" from your div if you are using it only to find controls. This makes your response slower.
You can simply access them as follows:
string txttermhouse = txttermhousenum.Text;
string txttermstr = txtxtermstreet.Text;
string txttermpostcode = txtxtermpost.Text;
You really don't need to find controls. You can access them directly.
You need to find control when its repeating inside grid column
template or within repeater etc., then you need to find control
otherwise you can access them directly.
I have an asp:login control on an .aspx page. I'm using a LayoutTemplate. When a user enters a wrong username or password, on postback, the password field appears to be filled. So if the user only changes the username and try to log in again, it returns an error. Debugging I've seen that the password is empty.
I've tested the same behavior using the default asp:login, without LayoutTemplate, and it works well. It means that after entering a wrong username or password, on postback, the password field appears empty.
How can I make it work?
EDIT:
This is the code I use. When something is wrong and postback occurs, password field appears filled. If the user clicks again to login, on debug mode, I see that the password is empty.
<asp:Login ID="lgLogin" runat="server"
FailureText="Wrong data"
TextLayout="TextOnLeft"
OnAuthenticate="lgLogin_Authenticate"
DestinationPageUrl="http://www.blablabla.com/"
OnLoginError="lgLogin_Error"
RenderOuterTable="false"
DisplayRememberMe="False">
<LayoutTemplate>
<div class="form-group">
<label for="lgLogin_UserName" class="col-md-4 control-label">Login <span class="require">*</span></label>
<div class="col-md-8">
<div class="input-icon">
<i class="fa fa-user"></i>
<asp:TextBox runat="server" type="text" ID="UserName" CssClass="form-control" />
</div>
</div>
</div>
<div class="form-group">
<label for="lgLogin_Password" class="col-md-4 control-label">Password <span class="require">*</span></label>
<div class="col-md-8">
<div class="input-icon">
<i class="fa fa-lock"></i>
<asp:TextBox runat="server" type="password" ID="Password" CssClass="form-control" />
</div>
</div>
</div>
<div id="AvisoError" runat="server" class="alert alert-danger" visible="false">
<button class="close" data-close="alert"></button>
<span>
<asp:Label ID="FailureText" runat="server" ></asp:Label>
</span>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
<asp:Button class="btn btn-primary" ID="LoginButton" runat="server" CommandName="Login" Text="Entrar" />
</div>
</div>
</LayoutTemplate>
<TextBoxStyle CssClass="form-control"/>
<LoginButtonStyle CssClass="btn btn-primary" />
If I use the default asp:login, if something goes wrong and postback occurs, password appears empty.
<asp:Login ID="lgLogin" runat="server"
FailureText="Wrong data"
TextLayout="TextOnLeft"
OnAuthenticate="lgLogin_Authenticate"
DestinationPageUrl="http://www.blablabla.com/"
RenderOuterTable="false"
DisplayRememberMe="False">
Obviously, you have set the textbox or input id to password field and it will go off when a postback occurs. Good practices are to leave it as it is and let user enter it one more time because there is a reason why this functionality has been there, and even if you want to push it anyhow then.
Firstly set your autocomplete property for the form to off. Then at page_load, store the password textbox value to some temp variable and then push that temp variable value to textbox. For more security, you can store that password field value to session and then encrypt it with base64 and then use it.
You need to add an attribute at the to retain the state of the controls after postback
Change type of field on load page event completed, works for me:
$(document).ready(function () {
document.getElementById("textBoxSenha").type = "password";
});
I have a code in my master page that I used placeholder to show and hide 2 different parts.It is completely works fine in all the Browsers, but it is not working on Iphone Even it is working on Android.
this is my code:
<div class="actions">
<asp:PlaceHolder ID="phLogout" runat="server">
<input TYPE="button" VALUE="Log Out" class="Button Orange" onclick="window.location.href = 'Logout.aspx'">
</asp:PlaceHolder>
<asp:PlaceHolder ID="phLogin" runat="server">
<p class="Title">Current users sign in:</p>
<asp:TextBox runat="server" ID="username" holder="Username"></asp:TextBox>
<asp:TextBox runat="server" ID="password" holder="Password" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Log In" class="Button Orange" OnClick="btn_login_Click" ></asp:Button>
<p class="Forgot">Forgot password?</p>
</asp:PlaceHolder>
</div>
I just found out that this part is not showing in the iphone with all the content inside the .
what I can use instead of tag?
I tried but all the styling gets off. Is the only tag replacing this so I may work more on style sheet or you are suggesting something else? Or even if the reason for not showing is the ?
I believe the "holder" attribute in your textboxes should be "placeholder" instead.
I am fairly new to C# and asp.net and am having trouble showing something submitted in a form. The form element is a tag. The drop-down info is pulled from a data base and displays correctly. It's just getting it to post to another page after the form is submitted is where I am having the problem. Any help would be appreciated.
Contact.aspx:
<form action="Default.aspx" method="post" data-transition="pop">
<div data-role="fieldcontain">
<label for="topEmails">Business Entity ID:</label>
<select name="topEmails" id="topEmails" data-native-menu="false"
runat="server">
</select>
</div>
<input type="submit" data-iconpos="right" data-inline="true"
data-icon="plus" name="sendMessage" id="sendMessage" value="Send Info">
</form>
Contact.aspx.cs:
AdventureWorks2012DataContext db = new AdventureWorks2012DataContext();
var emails = (from b in db.EmailAddresses
select new { b.EmailAddressID, b.BusinessEntityID }).Take(20);
topEmails.DataTextField = "BusinessEntityID";
topEmails.DataValueField = "BusinessEntityID";
topEmails.DataSource = emails;
topEmails.DataBind();
Default.aspx.cs:
FormSuccessBID.InnerHtml = "Business Entity ID: " + Request.Form["topEmails"] + "";
Any ideas why this wouldn't be working?
Update:
Contact.aspx:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h2 style="text-align: center;">Contact Kyle</h2>
<form action="Default.aspx" method="post" data-transition="pop">
<div data-role="fieldcontain">
<label for="userFName">First Name:</label>
<input type="text" name="firstName" id="uFName">
</div>
<div data-role="fieldcontain">
<label for="userLName">Last Name :</label>
<input type="text" name="lastName" id="uLName">
</div>
<div data-role="fieldcontain">
<label for="productsCategories">Products:</label>
<select name="productCategories" id="productCategories" data-native-menu="false" runat="server"></select>
</div>
<div data-role="fieldcontain">
<label for="topEmails">Business Entity ID:</label>
<select name="topEmails" id="topEmails" data-native-menu="false" runat="server"></select>
</div>
<input type="submit" data-iconpos="right" data-inline="true" data-icon="plus" name="sendMessage" id="sendMessage" value="Send Info">
</form>
</asp:Content>
You're missing "runat='server'" in your form definition.
In ASP.NET you're also allowed one form per page. Not sure from what you're posted if you're trying to put multiple forms on there, but if you are, it's not going to work.
I think all you need to do to accomplish what you want is have an ASP.NET button on the page, with the postbackURL set to the page you want to go to. (Of course, you need to do this in a server-side form)
I think you're mixing ASP.NET methods with other, different technologies. (From the look of it, you probably used classic ASP or PHP perhaps?)
If you can't use .NET for whatever reason, the ID/name of the field is not going to be what you're expecting. You need to inspect the form post and find its value - something along the lines of "clt00_somethingelse_topEmails". (Again, this is going to be a heck of a lot easier if you use the .NET way of doing things, but you may have a requirement not to)
Im using asp.net/c# weborms. I've added recaptcha to the form and used what is on their site. It needs a custom look hence it's like this:
<div id="recaptcha_widget" style="display:none">
<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color:red">Incorrect please try again</div>
<span class="recaptcha_only_if_image">Enter the words above:</span>
<span class="recaptcha_only_if_audio">Enter the numbers you hear:</span>
<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
<div>Get another CAPTCHA</div>
<div class="recaptcha_only_if_image">Get an audio CAPTCHA</div>
<div class="recaptcha_only_if_audio">Get an image CAPTCHA</div>
<div>Help</div>
</div>
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=your_public_key">
</script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=your_public_key"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
what do i need to do in the button_click method in the code behind iof the form to check if the words eneterd by the user is correct. same for audio.
Thanks
Why don't you use the control that is delivered with reCaptcha? Here is the control and a quickstart.
reCaptcha Quickstart & Control
Like other validations you just need to check if(Page.IsValid) in behind code. just note that you have to add recaptcha control in your code and then add your customs them.
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="your_public_key"
PrivateKey="Your_private_key" Theme="custom" />
<div id="recaptcha_widget" style="display:none">
<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color:red">Incorrect please try again</div>
...