|
For this code to work you need to add the attributes before the button is clicked.
So on the page load event do
if (!IsPostback)
{
Button1.Attributes.Add("onClick","window.print()");
}
Then it should work like you want it to.
Hope that helps.
Ben
|
|
|
|
|
the thing worked, but theer`s a little problem.
i want the button to go invisible, so that when the printing is done, the button does not show up.
right now as i click the button, the print window comes, and then the button goes invisible.
Kunal
|
|
|
|
|
You might want to get rid of the codebehind and do something like this:
Change this line:
Button1.Attributes.Add("onClick","window.print()");
to:
Button1.Attributes.Add("onClick","document.getElementById("+Button1.ClientId+").style.visibility = 'hidden';window.print();");
I think that should work for you.
Ben
|
|
|
|
|
kubben wrote: You might want to get rid of the codebehind and do something like this:
did get rid of the codebehind, removed the defintion for "Button1_Click".
and placed the following code in the page_load event
if (!IsPostBack)
{
Button1.Attributes.Add("onClick", "document.getElementById(" + Button1.ClientID + ").style.visibility = 'hidden';window.print();");
}
but nothing seems to happen at all. nor does the button disappear, and neither does the print window come up
Kunal
|
|
|
|
|
Ok I did a little playing. It looks like you will need to create a javascript funciton.
In the header section of your html page you need this function:
<head runat="server">
<title>Your page name here</title>
<script type="text/javascript" >
function doPrint(button)
{
button.style.visibility = "hidden";
window.print();
return false;
}
</script>
</head>
Then in the page load event do this:
Button1.Attributes.Add("onClick", "return doPrint(" + Button1.ClientID + ");");
That will work.
NOTE as soon as your page posts back to the server the print button will show up again.
Hope that helps.
Ben
|
|
|
|
|
thanks ben..
uve been a great help to me.. i dunno if ud remember helping me.. but i do remember the relief i get when i see the answer is from kubben in the forum..
i know.. this problem is no more a problem..
thx again...
Kunal
|
|
|
|
|
Glad I could help out. Sorry I didn't get it right the first time.
Ben
|
|
|
|
|
no problemo.. all is well that ends well..
Kunal
|
|
|
|
|
Hi guys, I need help to run this page (MoveGridRows.aspx) what is happening when i run on my localhost I do get the datagrid populated but when i click on the move up and move down button nothing hapenned. Infact i get an error on the status bar of the window
msdn.microsoft.com/msdnmag/issues/05/03/CuttingEdge/[^]
|
|
|
|
|
Hi
Can any one help me how to grab inner html from iframe using Java Script and use it in server side.i tried in several ways but failed to do so.
this is the javascript function i am using
function GetMsg()
{
document.getElementById("HidTemp").innerText =NewsBody_rich.document.body.innerHTML;
//document.getElementById("HidTemp").value=NewsBody_rich.document.body.innerHTML;
}
HidTemp = a HTML Hidden input Type;
NewsBody_rich = a iframe run at server;
and this is the code in .cs file on page load event.
btnSend.Attributes.Add("onClick", "GetMsg();");
btnsend= a asp:button
when i click on this button i am getting a error message
Sys.WebForms.PageRequestManagerServerException:an unknown error occured while processing request on server.the status code returned from the server was :500
please help me out this problem.
|
|
|
|
|
TRK@UK wrote: function GetMsg()
{
document.getElementById("HidTemp").innerText =NewsBody_rich.document.body.innerHTML;
//document.getElementById("HidTemp").value=NewsBody_rich.document.body.innerHTML;
}
Why don't you comment the first line and uncomment the commented line ? I don't think that HTML input hidden field is having innerText Property !
My suggestion is make the HidTemp to runat server. Then you can easily get the value on server side.
TRK@UK wrote: NewsBody_rich.document.body.innerHTML;
I think this will work only on IE...
|
|
|
|
|
Hi
I tried in both ways even making Hiddenbox to run at server.but i never understand the error which it is giving.
thnaks for reply..
|
|
|
|
|
Hi all,
I have a web page, where user can delete a record. I need to show a confirmation message and while googling i got the following code...
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return confirm('Are you sure you want to delete this record?');" OnClick="Button1_Click1" />
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return confirm(\'Are you sure you want to delete this record?\');");
}
This works fine, but i don't know how to track the user response. When user hits No, i should be able track "false". Please tell me how to achive this..
Thanks in advance
Sebastian
|
|
|
|
|
Sebastian T Xavier wrote: <asp:button id="Button1" runat="server" text="Button" <b="">OnClientClick="return confirm('Are you sure you want to delete this record?');" OnClick="Button1_Click1" />
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return confirm(\'Are you sure you want to delete this record?\');");
}
The parts bolded above essentially do the same thing. I would suggest you stick with the OnClientClick one.
Basically by saying "return confirm('...')" in the clientside click event, if the user clicks "cancel" then the server postback will not occur. Therefore all you need to do is handle the server side click as the action to take when the user wishes to delete and you can rest assure that if they do click cancel than the server side handler will not be entered.
|
|
|
|
|
|
Please help me this is my error
Object reference not set to an instance of an object(pointing this statement) Obj.addNewProject(txtProjectName.Text, txtProjectAbb.Text, txtClientSite.Text, cmbProjectManager.SelectedItem.Text, cmbProjectMember.SelectedItem.Text, ListBoxProjectMember.SelectedItem.Text, txtProDuration.Text, txtCompletionDate.Text, txtProjectDuration.Text, txtProDescription.Text)
*************
This is my Code for Button Save
************
Protected Sub ButtonSave1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSave1.Click
Dim Obj As Businesslayer.TimeSheet = New Businesslayer.TimeSheet
Obj.addNewProject(txtProjectName.Text, txtProjectAbb.Text, txtClientSite.Text, cmbProjectManager.SelectedItem.Text, cmbProjectMember.SelectedItem.Text, ListBoxProjectMember.SelectedItem.Text, txtProDuration.Text, txtCompletionDate.Text, txtProjectDuration.Text, txtProDescription.Text)
End Sub
**********
This is a class were I declared my variables
**********
Public Sub addNewProject(ByVal Project_Name As String, ByVal Project_Abb As String, ByVal Client_Name As String, ByVal Project_Manager As String, ByVal Project_Member As String, ByVal Project_Members As String, ByVal Est_Completion_Date As Date, ByVal Est_Project_Duration As Date, ByVal Project_Duration As Integer, ByVal Project_Description As String)
Dim Sql As String
Dim obj As Datalayer.Database = New Datalayer.Database
Sql = "insert into ProjectAdministration (Project_Name,Project_Abbreviation,Client_Name,Project_Manager,Project_Member,Project_Members,Est_Completion_Date,Est_Project_Duration,Project_Description,Confirm_Password,Project_Duration)" & _
" Values('" & Project_Name & "','" & Project_Abb & "','" & Client_Name & "','" & Project_Manager & "','" & Project_Member & "','" & Project_Members & "','" & Est_Completion_Date & "','" & Est_Project_Duration & "', '" & Project_Duration & "','" & Project_Description & "')"
obj.Execute(Sql)
End Sub
**********
I really don't understand this error.Can you please help me with it,What might be the problem?
Thanking you in Advance
oga m
|
|
|
|
|
It is hard to say what the problem is, but I would suggest that you put a break point in the code. Then check the objects to figure out which object is still set to Nothing. Once you figure out which object is set to Nothing then you might have a better idea of what is going on. If for some reason the code is getting executed in the load event the text boxes would not exist yet. Anyway, just a thought, hope it helps.
Ben
|
|
|
|
|
Oga M wrote: Object reference not set to an instance of an object(pointing this statement) Obj.addNewProject(txtProjectName.Text, txtProjectAbb.Text, txtClientSite.Text, cmbProjectManager.SelectedItem.Text, cmbProjectMember.SelectedItem.Text, ListBoxProjectMember.SelectedItem.Text, txtProDuration.Text, txtCompletionDate.Text, txtProjectDuration.Text, txtProDescription.Text)
Usually this error will come when you are trying to use an object that is not been initialized yet. Make sure all objects are initialized before you use them.
|
|
|
|
|
My codes is shown below. Hopefully it should create a dataset. But how do I create a dataset in code using these values. Something like
<br />
Dim NewDataSet AS Dataset MadData.Cusomer_Lookup(Parameters here)
?
Public Class MadData<br />
'get application settings<br />
<br />
<br />
<br />
<br />
Public connectionString As String = ConfigurationManager.ConnectionStrings("MADConnectionString").ConnectionString<br />
<br />
Public Function Customer_Lookup(ByVal CustomerType As Integer, ByVal CustomerForename As String, ByVal CustomerSurname As String, ByVal LimitedTradingName As String, ByVal NonTradingName As String, ByVal AddressMobile As String, ByVal Records As Integer, ByVal Query As String) As DataSet<br />
<br />
'get the entity name to use for the DataSet table<br />
Dim dbConnection As New SqlConnection(connectionString)<br />
Dim dbDataSet As New DataSet<br />
<br />
Try<br />
'Create Command object for sp<br />
Dim dbCommand As SqlCommand = New SqlCommand("Customer_Lookup", dbConnection)<br />
dbCommand.CommandType = CommandType.StoredProcedure<br />
<br />
'input parameter variables - CustomerType<br />
Dim dbParameter As SqlParameter = dbCommand.Parameters.Add("@CustomerType", SqlDbType.Int)<br />
dbParameter.Direction = ParameterDirection.Input<br />
dbParameter.Value = CustomerType<br />
<br />
'input parameter variables - CustomerForename<br />
Dim dbParameter1 As SqlParameter = dbCommand.Parameters.Add("@CustomerForename", SqlDbType.VarChar)<br />
dbParameter1.Direction = ParameterDirection.Input<br />
dbParameter1.Value = CustomerForename<br />
<br />
'input parameter variables - CustomerSurname<br />
Dim dbParameter2 As SqlParameter = dbCommand.Parameters.Add("@CustomerSurname", SqlDbType.VarChar)<br />
dbParameter2.Direction = ParameterDirection.Input<br />
dbParameter2.Value = CustomerSurname<br />
<br />
'input parameter variables - LimitedTradingName<br />
Dim dbParameter3 As SqlParameter = dbCommand.Parameters.Add("@LimitedTradingName", SqlDbType.VarChar)<br />
dbParameter3.Direction = ParameterDirection.Input<br />
dbParameter3.Value = LimitedTradingName<br />
<br />
'input parameter variables - NonTradingName<br />
Dim dbParameter4 As SqlParameter = dbCommand.Parameters.Add("@NonTradingName", SqlDbType.VarChar)<br />
dbParameter4.Direction = ParameterDirection.Input<br />
dbParameter4.Value = NonTradingName<br />
<br />
'input parameter variables - AddressMobile<br />
Dim dbParameter5 As SqlParameter = dbCommand.Parameters.Add("@AddressMobile", SqlDbType.VarChar)<br />
dbParameter5.Direction = ParameterDirection.Input<br />
dbParameter5.Value = AddressMobile<br />
<br />
'input parameter variables - Records<br />
Dim dbParameter6 As SqlParameter = dbCommand.Parameters.Add("@Records", SqlDbType.Int)<br />
dbParameter6.Direction = ParameterDirection.Input<br />
dbParameter6.Value = Records<br />
<br />
'input parameter variables - Query<br />
Dim dbParameter7 As SqlParameter = dbCommand.Parameters.Add("@Query", SqlDbType.VarChar)<br />
dbParameter7.Direction = ParameterDirection.Input<br />
dbParameter7.Value = Query & "%"<br />
<br />
'open the Connection; run the sp; transform to a DataSet<br />
Dim dbDataAdapter As SqlDataAdapter = New SqlDataAdapter(dbCommand)<br />
dbDataAdapter.Fill(dbDataSet)<br />
<br />
Catch ex As System.Exception<br />
<br />
Throw ex<br />
<br />
<br />
Finally<br />
'tidy up<br />
dbConnection.Close()<br />
dbConnection.Dispose()<br />
<br />
End Try<br />
<br />
Return dbDataSet<br />
<br />
End Function<br />
<br />
End Class
|
|
|
|
|
You're missing an equals sign, but yes.
|
|
|
|
|
|
|
hi vasudevan and thanx for your reply.
It's not what i've been searching for, but surely it puts me on he right direction. Anyway, i'm not an Ajax programer and examples like you gave me helps a lot to learn. And nice scripts too must say.
cheers!
"I hated myself... no, I hated my place in the world" - From Jerry Maguire
|
|
|
|
|
how many columns datagrid hav ??
|
|
|
|
|
The screen real estate, good user experience of the application and Memory alone would dictate this limit right?
|
|
|
|
|