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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid ItemCommand - Run RegisterStartupScript

Status
Not open for further replies.

Creepers

Programmer
Nov 11, 2002
116
US
I am wanting to open a new browser window when a user clicks Edit button column. Howerver the below code does not work:

Private Sub grdChats_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdChats.ItemCommand
Dim ChannelID_ls As String
Dim SubjectID_ls As String
Dim Script_ls As String

ChannelID_ls = e.Item.Cells(0).Text
SubjectID_ls = e.Item.Cells(1).Text

Me.lblInfo.Text = ChannelID_ls & " " & SubjectID_ls

Script_ls = "<script type='text/javascript'>detailedresults=window.open('ChatWin.aspx?Channel=" + ChannelID_ls + "&Subject=" + SubjectID_ls + ",'Chat','height=325px,width=456px,top=200,left=350');</script>"
RegisterStartupScript("ChatScript", Script_ls)
End Sub

Is this possible??
 
Have a look at the HTML that is rendered to the page. Is the javascript actually rendered? Does the js do what it is supposed to do if you add it to a HTML page?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
I think i see what your trying to do.
1. load grid with edit button
2. click edit
3. post back to server
4. create javascript
5. render page to client
6. have javascript execute.

why not just have the edit button pop up a window without the post back. i also don't understand this line of code either
Code:
detailedresults=window.open('ChatWin ...

try this instead:
Code:
//aspx
<asp:GridView ...>
   <Columns>
      <asp:BoundField ... />
      <asp:TemplateField>
         <ItemTemplate>
            <asp:Button id="editButton" runat="server" text="Edit" />
         <ItemTemplate>
      </asp:TemplateField>
   </Columns>
</asp:GridView>


//code behind (c#)
protected void GridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowIndex > -1)
   {
      [object] data = ([object])e.Row.DataItem;
      int channel = data.ChannelId;
      int subject = data.SubjectId
      string js = string.Format("window.open('ChatWin.aspx?Channel={0}&Subject={1},'Chat','...'); return false;", channel, subject);

      Button editButton = (Button)e.Row.FindControl("editButton");
      editButton.Attributes.Add("onclick", js);
   }
}
when your page is loaded the edit button will open the window without a post back.

Notes:
the [tt]return false;[/tt] this prevents the submit behavior.
replace [tt][object][/tt] with your data type. it may be a DataViewRow or a custom object.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top