AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Gridview in updatepanel is not opening new window on row command.
Posted by Sam on  4/15/2010 12:49:16 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Gridview in updatepanel is not opening new window on row command.When i do it without update pannel it is wokring fyn.So please help me ASAP.
my code is below.
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_search" />
<asp:AsyncPostBackTrigger ControlID="gvw" EventName="RowCommand" />
</Triggers>
<ContentTemplate>


<asp:GridView ID="gvw" runat="server" DataKeyNames="Companyid"
AutoGenerateColumns="false" HeaderStyle-BackColor="#9FCFFF" HeaderStyle-HorizontalAlign="Center" RowStyle-HorizontalAlign="Center"
onselectedindexchanging="gvw_SelectedIndexChanging" Width="753px" OnRowCommand="gvw_RowCommand">

<Columns>
<asp:TemplateField HeaderText="Company Name" ItemStyle-Width="13%">
<ItemTemplate>
<asp:Label ID=sdhd runat="server" Text='<%#Eval("Companyname")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="20%" />
</asp:TemplateField>


<asp:TemplateField HeaderText="City" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lbl_city" runat="server" Text='<%#Eval("city")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone No." ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lbl_phone" runat="server" Text='<%#Eval("phoneno")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Email-Id" ItemStyle-Width="20%">
<ItemTemplate>
<asp:Label ID="lbl_email" runat="server" Text='<%#Eval("Email")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Industry" ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lbl_IndustrySector" runat="server"
Text='<%#Eval("IndustrySector")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" ItemStyle-Width="5%">
<ItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#Eval("Status")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>

<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:button id="vw" runat="server" CommandName="Select" Text="View & Update" CssClass="button_login_d" Width="120px"/>
<asp:button id="Button1" runat="server" CommandName="View" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" Text="View Contact" CssClass="button_login_d" Width="120px"/>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>


</Columns>

<HeaderStyle BackColor="#9FCFFF" />

</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>





.cs
protected void gvw_RowCommand(object sender, GridViewCommandEventArgs e)
{

if (e.CommandName == "View")
{
int i = Convert.ToInt32(e.CommandArgument);
Session["k1"] = gvw.DataKeys[i].Value.ToString();
string strScript = "<script> ";
strScript += "var newWindow = window.open('Contactforcompany.aspx', '_blank','height=250, left=150px, top=230px,center:yes, width=730, status=no, resizable= yes, menubar=no, toolbar=no, location=no, scrollbars=no, status=no');";
strScript += "</script>";
this.Page.RegisterClientScriptBlock("strScript", strScript);

}
}

Post Your Reply Post New Question

 Viewer's Reply
Opening New Window From Ajax UpdatePanel in GridView
Answered By Moderator1 on 4/17/2010 7:56:02 PM
Hi,

Try to use PostBackTrigger with the UpdatePanel and mention the ControlID as "gvw"

<asp:PostBackTrigger ControlID="gvw" />

But all the GridView actions will create post back. Without this you cannot open new Window in GridView.
 
Gridview in updatepanel is not opening new window on row command.
Answered By Sharmeek Parmar on 4/30/2010 1:16:00 AM
Thnx....a lil problem is still there.When new window is opening whole parent page is doing postback.I think i have to make some chage in Window.Open().Please give some suggestion.


Sharmeek Parmar
 
Open New Window From PostbackTrigger event
Answered By Moderator1 on 6/21/2010 2:53:17 AM
Hi,

You can do either one, but not both.. New window can be opened only you perform a PostBackTrigger, if you perform PostBackTrigger the parent window will do postback..
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Simply JavaScript - Free 150 Page Preview!
Everything You Know About CSS Is Wrong! - Free 37 Page Preview!
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!