printer

collie

New member
printer

Hi, I have a form with a button. When the user clicks the button I want it to automatically print the form. I don't want the print dialog box to appear as what happens with the command windows.print(). Is it possible to print directly to the printer? Thanks​
 

gilad g

New member
nope ../images/Emo4.gif

Personally, as a user, I wouldn't want any website to just start printing its contents without me confirming it first, so it makes sense
 

collie

New member
scrollbar

Thanks for the reply about the printer. Another question if you don't mind: I have a repeater on my form that appears if there is an error in one of the textboxes after the user clicked the save button. After the user clicked the button and if the repeater appears how can i set the scrollbar to be positioned where the repeater is? Thanks​
 

yuval k

New member
Hmmm....

Either redirect to an anchor on your page (pageURL#anchorName), and the browser will autoscroll there (it won't reload the page AFAIK), or use JavaScript. If you know its exact position you can use scrollTo. If you only know its position below the current position, use scrollBy.​
 

collie

New member
multiple buttons

Hi, I am not sure if this is the right forum but i will try asking anyway. I have an aspx page with multiple buttons. I want to avoid postback so i want to use js. When i click on the buttons each takes me to the same page just with a different aprst: practice.aspx?aprst= I tried the following but nothing happens when i click the buttons: aspx: <script language="javascript"> function SbtForm (aspr) { if (aspr == "ads") { document.Form1.submit ="practice.aspx?aprst=1"; } if (aspr=="new") { document.Form1.submit ="practice.aspx?aprst=0"; } } </script> </HEAD> <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1" align="center"> <TR> <TD> <asp:Button id="btnAllAds" runat="server" Text="מודעות " Width="92px"></asp:Button></TD> <TD> <asp:Button id="btnNewAds" runat="server" Text="מודעות חדשות" Width="121px"></asp:Button></TD> </TR> vb.aspx: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here btnAllAds.Attributes.Add("onClick", "SbtForm ('ads');") btnNewAds.Attributes.Add("OnClick", "SbtForm ('new');") End Sub​
 

gilad g

New member
oh, of course

Didn't see it before -- You have to associate the button with your function!​
 

collie

New member
u mean like this:

btnAllAds.Attributes.Add("onClick", "SbtForm ('ads');")? If yes, then it still doesn't work.​
 

collie

New member
now i get an error message

I have modified the js to: function SbtForm (aspr) { if (aspr == "ads") { document.Form1.action = "practice.aspx?aprst=1"; } if (aspr=="new") { document.Form1.action="practice.aspx?aprst=0"; } document.Form1.submit() } </script> It now takes me to another page but with the following error: The viewstate is invalid for this page and might be corrupted. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The viewstate is invalid for this page and might be corrupted. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [HttpException (0x80004005): The viewstate is invalid for this page and might be corrupted.] System.Web.UI.Page.LoadPageStateFromPersistenceMedium() System.Web.UI.Page.LoadPageViewState() System.Web.UI.Page.ProcessRequestMain() -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
 

collie

New member
it works fine if i redirect it to

a normal asp page. it doesn't work in aspx though.​
 

gilad g

New member
Hmmm

Just to make sure - when you added the location.href ="" command, did you delete the sumbit command as well? can i see your code after the changes you made?​
 

collie

New member
code

aspx: <%@ Page Language="vb" AutoEventWireup="false" src="buttons.aspx.vb" Inherits="buttons"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>NavForm</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="VBScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <script language="javascript"> function SbtForm (aspr) { if (aspr == "payads") { document.Form1.action = "practice.aspx?aprst=1"; } if (aspr=="new") { location.href="practice.aspx?aprst=0"; } if (aspr=="cancel") { location.href="practice.aspx?aprst=-2"; } if (aspr=="error") { location.href="practice.aspx?aprst=-1"; } if (aspr=="other") { location.href="practice.aspx"; } } </script> </HEAD> <body> <form id="Form1" method="post" runat="server"> <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" align="center" border="1"> <TR> <TD> <asp:Button id="btnCancel" runat="server" Text="Cancel"></asp:Button></TD> <TD> <asp:Button id="btnNew" runat="server" Text="New"></asp:Button></TD> </TR> </TABLE> </form> </body> </HTML> aspx.vb Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here btnNew.Attributes.Add("onclick", "SbtForm ('new'); ") btnCancel.Attributes.Add("onclick", "SbtForm ('cancel') ; return false;") End Sub​
 

gilad g

New member
../images/Emo62.gif

I think i know why he is giving you this error. when you are redirecting, ASP.NET thinks it was a postback, and tries to load the viewstate, but since no viewstate data was sent to the server, he shoots out an error. what i suggest doing, is instead of using the QueryString, consider using a hidden form variable: <input type="hidden" name="aprst" value="" id="myHidden" /> ... and the jscript function: document.getElementById("myHidden").value = "whatever"; document.myForm.submit(); //Add this line, or nothing will happen! After the form was submitted (ie, we simulated a postback), use Request.Form["aprst"] to get the value. Hope this works
 

collie

New member
pleeze help

Hi, I don't understand exactly how to submit the form to another page. This is what i did so far: ASPX: function sbtBtns (aspr) { if (aspr == "cancel") { document.getElementById("myHidden").value = "cancel"; } if (aspr=="new") { document.getElementById("myHidden").value = "new"; } document.Form1.submit(); } </script> <form id="Form1" method="post" runat="server" > <asp:Button id="Button1" runat="server" Text="new"></asp:Button> <asp:Button id="Button2" runat="server" Text="cancel"></asp:Button> <input type=hidden id=myHidden name=myHidden value=""> </form> aspx.vb: Button1.Attributes.Add("onclick", "sbtBtns('new');") Button2.Attributes.Add("onclick", "sbtBtns('cancel');")​
 
למעלה