Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I pop up a alert window for a linkbutton 1

Status
Not open for further replies.

compu66

Programmer
Dec 19, 2007
71
US
Hi all,

I have a link button(btnsave).
In the application there is btnsave_click handled.
for this i am trying to pop up the javascript alert window.
in .vb
btnSave.Attributes.Add("onclick", "javascript:ShowAlert();")
In the .aspx file
i wrote

function showalert(){

alert("this is already there")
}
as far as i know when i wrote the same for hte button it worked but here its hyperlink ,will javascript work for hyperlink??

I felt its regarding hyperlink so I posted this.

Thanks for any help in advance.

 
hey sorry its not hyperlink but a linkButton
 
I searched this online and could know how to pop up a window
but i want it only when the label text is not changed.

if used similar to the below one i.e onclientclick it is giving pop up confirm window but irrespective of the condition.
how to do the same with the condition.



<asp:LinkButton ID=”lbtnDelete” runat=”server” CommandName=’DeleteItem’ Text=’Delete’ OnClientClick=”return confirm(’Are you sure you want to\ndelete this item?’);”></asp:LinkButton>
 
You will have to check the label text and if it's changed, then add an onclick attribute.
 
Hey i wrote this but the popup doesnot show
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim dh As New DAL.DataHandlerReports
If (String.IsNullOrEmpty(lblMamCatDescription.Text)) Then
btnSave.Attributes.Add("onclientclick", "javascript:ShowAlert();")

Else
lblMamCatDescription.Text = sMamCatMsg

'Set the transcribed date to today since the user is clicking 'save'
txtTransDate.Text = Now.ToShortDateString()

Update_Event("noupdate")
Me.nAccessionNumber = Me.txtAcc1.Text.Trim()

dh.LogPageAccess(Me.lblPatientID.Text.Trim(), CommonFunctions.GetCookie(Request, "ID"), Convert.ToInt32(Me.txtAcc1.Text.Trim()), DateTime.Now, "Transcibe - Save")

Get_Info(Me.nAccessionNumber)

dh = Nothing
End If
End Sub
 
You will need to add the onclick event on the page load event and perform the check for an empty text box value in javascript.

Think about what you have at the minute. You have the check in the click event, so the usere clicks the button, it posts back and then you add add the onclick event! So, the link now has an alert pop up only if the user clicks the link for a second time.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Another alternative would be to use the method you are now, but instead of adding an onclick event, just register the alert to pop up. You can use ClientScript.RegisterStartUpScript to register any javascript calls that you want to occur when the page loads.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top