Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using a repeater control to display records,I m using javascript window.open to edit a record

I am having a problem in it that when i click on Update button first time it doesnot open window one should click second time on the button

Why is this problem arising?

Second i want to know how can i rebind repetear after updating the record

Third how can i close the opened javascript window just after updating record
Repeater Item Command ===>
<pre lang="cs">protected void rptuser_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            Usercls u = new Usercls();
            if (e.CommandName == "upd")
            {
                int uid = Convert.ToInt32(e.CommandArgument);
                Session["uid"] = u.GetUserbyID(uid)[0].UserId.ToString();
                Session["fname"] = u.GetUserbyID(uid)[0].FirstName;
                Session["lname"] = u.GetUserbyID(uid)[0].LastName;
                Session["uname"] = u.GetUserbyID(uid)[0].Username;
                Session["des"] = u.GetUserbyID(uid)[0].Designation;
                ImageButton upd = (ImageButton)e.Item.FindControl("updbtn");
                upd.OnClientClick = "return PopUp()";
            }
            else if (e.CommandName == "del")
            {
                int uid = Convert.ToInt32(e.CommandArgument);
                u.DeleteUser(uid);
                rptuser.DataBind();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }



Repeater ===>
<pre lang="xml"><asp:Repeater ID="rptuser" runat="server" DataSourceID="ObjectDataSource1"
               OnItemCommand="rptuser_ItemCommand">
       <HeaderTemplate>
       <table>
       <tr>
       <td class="GridHeader"></td>
       <td  class="GridHeader">UserID:</td>
       <td class="GridHeader">FirstName:</td>
       <td class="GridHeader">LastName:</td>
       <td class="GridHeader">Designation:</td>
       <td  class="GridHeader">UserName:</td>
       <td class="GridHeader"></td>
       </tr>
       </HeaderTemplate>
       <ItemTemplate>
       <tr>
        <td class="GridItems"><asp:ImageButton runat="server" ID="delbtn" ImageUrl="~/images/delete.gif" CommandName="del" CommandArgument='<%# Eval("UserId") %>' OnClientClick="return confirm('Are you sure to delete this User')"  ValidationGroup="ab" ToolTip="Delete User"  /></td>
        <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"UserId") %></td>
        <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"FirstName") %></td>
        <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"LastName") %></td>
        <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"Designation") %></td>
        <td class="GridItems"><%# DataBinder.Eval(Container.DataItem,"Username") %></td>
        <td class="GridItems"><asp:ImageButton ID="updbtn"   ValidationGroup="Av" runat="server" ImageUrl="~/images/update.jpg"   CommandName="upd" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"UserId") %>' /></td>
       </tr>
       </ItemTemplate>
       <FooterTemplate>
       </table>
       </FooterTemplate>
       </asp:Repeater>



If i use OnClientClick inside repeater,it gives exception as it doesn't find appropriate session object
Posted

When you first click it binds the client script to popup. And that is why you have to click it again to get the popup.

Change upd.OnClientClick = "return PopUp()"; to ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", "window.open('urlhere');", true);
 
Share this answer
 
v3
Comments
Syed Salman Raza Zaidi 1-Feb-11 7:58am    
Problem Still Exists :(
Prerak Patel 1-Feb-11 8:08am    
Sorry, please try ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", "window.open('urlhere');", true);
can u share the PopUp()js function
 
Share this answer
 
Comments
Syed Salman Raza Zaidi 1-Feb-11 8:05am    
function PopUp()
{
var winTop = (screen.height / 2) - 125;
var winLeft = (screen.width / 2) - 125;
var windowFeatures = "width=300,height=250,";
windowFeatures = windowFeatures + "left=" + winLeft + ",";
windowFeatures = windowFeatures + "top=" + winTop;

window.open("EditUser.aspx","EditUser",windowFeatures);
}
Ibrahim.Poonawala 1-Feb-11 8:25am    
on the first click your upd.OnClientClick = "return PopUp()"; is getting registered and then on second click it actually gets popup. so you need to register the click event on page load.

updbtn.Attributes.Add("onClick", "window.open('EditUser.aspx','','width=700,height=700');return false;");
Ibrahim.Poonawala 1-Feb-11 9:34am    
this works.. i have checked...U need to add this event

protected void rptuser_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton _myButton = (ImageButton)e.Item.FindControl("updbtn");
_myButton.Attributes.Add("onClick", "window.open('About.aspx','','width=700,height=700');return false;");
}
}
2) If you are populating the repeater like in Bind() method call the method after updating.
private void Bind()
    {
        //connection command datatable...      
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }

3)Check here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900