?
Solved

vb.net and javascript

Posted on 2011-05-05
9
Medium Priority
?
227 Views
Last Modified: 2012-05-11
Hello,

I currenty have an area in my gridview where i have a hyperlink
     <asp:HyperLink ID="HyperLink1" onclick="openedit()" style="cursor:hand; cursor:pointer"  runat="server">Edit</asp:HyperLink>

Open in new window


When clicking on the hyperlink it does openedit()
function openedit() {
    window.open("editpostadmin.aspx",
       "mywindow", "menubar=0,resizable=0," +
       "width=350,height=250,toolbars=0");

}

Open in new window


what i want to do is make my link : editpostadmin.aspx contain the gridview row ID.

so editpostadmin.aspx?id=?

i can get the id via e.Row.DataItem("ID") but how do i add it to the javascript page.
0
Comment
Question by:runnerjp2005
  • 4
  • 4
9 Comments
 
LVL 6

Expert Comment

by:bartvd
ID: 35698641
You can just type window.open("editpostadmin.aspx?id=1",

with the correct id
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35698649
Hi,
in following onclick should be a serverside event not client side
<asp:HyperLink ID="HyperLink1" onclick="openedit()" style="cursor:hand; cursor:pointer"  runat="server">Edit</asp:HyperLink>

so you may use

<asp:HyperLink ID="HyperLink1" style="cursor:hand; cursor:pointer"  runat="server">Edit</asp:HyperLink>

function openedit() {  
    window.open("editpostadmin.aspx",  
       "mywindow", "menubar=0,resizable=0," +  
       "width=350,height=250,toolbars=0");  
   return false;  
}


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        HyperLink1.Attributes.Add("onclick", "return openedit();")
End Sub
0
 

Author Comment

by:runnerjp2005
ID: 35698664
yes but the id changes depending on the post....

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35698666
if it is in grid view then use follwoing


function openedit(id) {  
    window.open("editpostadmin.aspx?id" +id,  
       "mywindow", "menubar=0,resizable=0," +  
       "width=350,height=250,toolbars=0");  
   return false;  
}


in row databound
        HyperLink1.Attributes.Add("onclick", "return openedit(" + yourIDfiled  +");")
0
 

Author Comment

by:runnerjp2005
ID: 35698677
so editpostadmin.aspx?id= (e.Row.DataItem("ID"))
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35698688
function openedit(id) {  
    window.open("editpostadmin.aspx?id=" +id,  
       "mywindow", "menubar=0,resizable=0," +  
       "width=350,height=250,toolbars=0");  
   return false;  
}

HyperLink1.Attributes.Add("onclick", "return openedit(" + e.Row.DataItem("ID") +");")
0
 

Author Comment

by:runnerjp2005
ID: 35698810
I have tried the below and get
Conversion from string "return openedit(" to type 'Double' is not valid.

<asp:HyperLink ID="HyperLink1" onclick="openedit()" style="cursor:hand; cursor:pointer"  runat="server">Edit</asp:HyperLink>

 Dim HyperLink1 As HyperLink = CType(e.Row.FindControl("HyperLink1"), HyperLink)
            Dim thegridid As Integer = e.Row.DataItem("ID")
            HyperLink1.Attributes.Add("onclick", "return openedit(" + thegridid + ");")

Open in new window

0
 
LVL 16

Accepted Solution

by:
Imran Javed Zia earned 2000 total points
ID: 35698836
if you are getting error on following:
HyperLink1.Attributes.Add("onclick", "return openedit(" + thegridid + ");")

then use as following:
        HyperLink1.Attributes.Add("onclick", "return openedit(" + thegridid.ToString() + ");")
0
 

Author Closing Comment

by:runnerjp2005
ID: 35698918
well done!!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question