<asp:checkbox> vs <input type="checkbox">
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: <asp:checkbox> vs <input type="checkbox">

  1. #1
    Join Date
    Mar 2007
    Posts
    238

    <asp:checkbox> vs <input type="checkbox">

    HI All,
    I need to be able to assign a value to my checkbox, so that when the user checks it, the c# code will know what value has been checked. In a plain html tags we can use value attribute to assign a value i.e., <input type="checkbox" id="chk1" value="1">. But <asp:checkbox doesn't have a value field, and i found out that i can use <asp:checkboxlist> & <listItem>.
    The actual value is coming from the database like this

    [code]

    <%#DataBinder.Eval(Container.DataItem, "FullName") %>



    {/code]

    When I run the page i get databounding expressions are only supported on objects that have a databinding event....... Is there any way around to this problem.

    THanks!

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: <asp:checkbox> vs <input type="checkbox">

    You don't need a value field for a asp:checkbox.
    There is a checked property to indicate whether or not the checkbox is checked on post back.

    http://msdn.microsoft.com/en-us/libr...x.checked.aspx

  3. #3
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    I understand the point. But I need to pickup a value if this check box is clicked, true/false won't be enough. The checkbox is inside a <asp:repeater> so the value of the checkbox changes according to the row in question. The idea is the user checks the box and click a button and the event handler method will do the needful according to the value provided by the checkbox.
    Hope i make sense. Any more suggestion?
    THanks

  4. #4
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Smile Re: <asp:checkbox> vs <input type="checkbox">

    Do you mind doing that through code? Then it is easy enough to set the value of the text property of asp:checkbox inside the repeater. Suppose your html code is something like

    Code:
            <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:Repeater EnableViewState="true" ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
            <ItemTemplate>
                <asp:CheckBox ID="mycheckbox" Text='<%#DataBinder.Eval(Container.DataItem, "field1") %>' runat="server" />
            </ItemTemplate>
            </asp:Repeater>
            <asp:Button ID="mybutton" runat="server" Text="Submit" OnClick="mybutton_Click" />
    Then you can use the code given below in your code behind.

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection con = new SqlConnection("your connection string");
                string sql = "select field1 from table1";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds, "MyTable");
                Repeater1.DataSource = ds;
                Repeater1.DataBind();            
            }
            Label1.Text = "";
        }
        protected void mybutton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Repeater1.Controls.Count; i++)
            {
                try
                {
                    CheckBox chk = (CheckBox)Repeater1.Controls[i].FindControl("mycheckbox");
                    if (chk.Checked)
                        Label1.Text += chk.Text + " is checked, ";
                    else
                        Label1.Text += chk.Text + " is not checked, ";
                }
                catch
                {
                }
            }
        }
    I have assumed a field name of field1 and a table name of table1. Using this code in a default page will put the text values of the check box in each row of repeater1 equal to the value of field1. Then if you check or uncheck the check boxes and click on the button, in the mybutton_Click procedure you can find out which check box is clicked as shown in the code. This is printed in Label1.

    Hope this helps.

    Warm Regards.
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

  5. #5
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    Thanks for your reply.
    My column needs to have a checkbox and a hyperlink that users can click. So i can't have a text property for the checkbox. Bascially it should be a checkbox with just a value attached to it.

  6. #6
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Smile Re: <asp:checkbox> vs <input type="checkbox">

    Try this. You can easily replace a web server control check box with a html input checkbox. Your html code would be.

    Code:
        <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:Repeater EnableViewState="true" ID="Repeater1" runat="server">
            <ItemTemplate>
                <input type="checkbox" id="mycheckbox" value='<%#DataBinder.Eval(Container.DataItem, "field1") %>' runat="server" />
            </ItemTemplate>
            </asp:Repeater>
            <asp:Button ID="mybutton" runat="server" Text="Submit" OnClick="mybutton_Click" />
    Here you can have a html check box with a value set inside a repeeater

    And your code behind would have

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection con = new SqlConnection("your connection string");
                string sql = "select field1 from table1";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds, "MyTable");
                Repeater1.DataSource = ds;
                Repeater1.DataBind();
            }
            Label1.Text = "";
        }
        protected void mybutton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Repeater1.Controls.Count; i++)
            {
                try
                {
                    HtmlInputCheckBox chk = (HtmlInputCheckBox)Repeater1.Controls[i].FindControl("mycheckbox");
                    if (chk.Checked)
                        Label1.Text += "Checkbox with value " + chk.Value + " is checked, ";
                    else
                        Label1.Text += "Checkbox with value " + chk.Value + " is not checked, ";
                }
                catch
                {
                }
            }
        }
    If you put this code in a default page and place the proper connection string, fields and tables you will get your repeater with check boxes that have a value associated with them but no text. On clicking the button a label will display the details of check boxes and their values and also tell you whether they were checked or not. I have assumed a field name of field1 and a table name of table1 which can be easily replaced.

    The point is even though they are html check boxes they still have the runat="server" tag attached to them and are essentially server controls. If you need a check box that is fully a html control and no runat="server" tag attached there are still ways to do that.

    If what I have given now does not satisfy your need let me know. I am not clear about the link part of your statement though.

    Hope this helps.

    Warm Regards.
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

  7. #7
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    Using <input type=checkbox> is ideally what i wanted. THanks for suggesting that.

    In the onbuttonclick, i can't see the checkbox being clicked.

    Code:
    private void onbuttonclick(object sender, System.EventArgs e){
      for(int i=0; i<Repeater1.Items.Count; i++){
         HtmlInputCheckBox mychk = (HtmlInputCheckbox)Repeater1.Items[i].FindControl("mycheckbox");
    
            if(mychk.checked){
          
                  string strvalue = mychk.value;
                  btn.Attributes.add("onclick", window.open('targetpage.aspx?filename='+strvalue,'','Height=400,width=400')");
    
             }//if
    
       }//for
    
    }//method
    I always get the if condition false even if the checkbox is checked. I tried with the simple <asp:checkbox> to see if after clicking the button, the onclick code knows the checkbox is clicked, no, it's still the same. But if the page loads with checkbox checked, then the onclick button knows it. Am i missing something here?

    Thanks for you time.

    I had Ispostback function at the wrong place in the page-load....it is working now.

    But i can't make the popup window appear at the first click of the button. It works only the second time. Also, if i have the arguments in the url(in window.open) it doesn't work. Any suggestion?
    Last edited by tarunk; March 12th, 2009 at 08:25 AM. Reason: adding

  8. #8
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    Window.open function does nothing if the first argument is a string variable.
    Code:
     if(mychk.checked){
          
                  string strvalue = mychk.value;
                  string strUrl = "targetpage.aspx?filename=";
                  strUrl += strvalue;
                  btn.Attributes.add("onclick", window.open(strUrl,'','Height=400,width=400')");
    
             }//if
    HOw manyever times you click the button, it goes to this code and does nothing. But hardcode the url in the window.open, it opens the file at the second click of the button.

    I clicked on view source of the page after clicking the button, it displays as
    Code:
    <input type="submit" name="btn" onclick="window.open(strUrl,'','','height=400,width=400')"
    Isn't the strUrl should be interpreted in the view source.
    Any suggestion is welcome as I am spending hours on just this control.

  9. #9
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Re: <asp:checkbox> vs <input type="checkbox">

    Hi Tarunk,

    I think we are talking at cross purposes. I will state your requirement as I understand it and give you a sample application. If it is not correct let me know what exactly you need so that I can help you further. As I understand it you want to have an input check box and an input button in each row of a repeater. The check box should have a value associated with it which comes from a field in a table in your database.

    Now on clicking the button on any row of the repeater you want to open a page called targetpage.aspx and pass the value associated with the input check box on that row to this page, if the check box on that row is checked. IF the check box is not checked then nothing should happen.

    This can be done using a combination of javascript and c#. I will give you a sample application which you can try out. First open up a default web site in VS2005. It will have a page called Default.aspx in it. Substitute the html code given below for Default.aspx

    Html code for default.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">
        function openfunc(id)
        {
          var chk = document.getElementById(id);
          if(chk.checked)
          {
             var url = "targetpage.aspx?filename=" + chk.value;
             window.open(url, 'target', 'Height=400,width=400');
          }
          return false;   
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:Repeater EnableViewState="true" ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
            <HeaderTemplate><table width= "100%"></HeaderTemplate>
            <ItemTemplate>
               <tr><td>
                <input type="checkbox" id="mycheckbox" value='<%#DataBinder.Eval(Container.DataItem, "field1") %>' runat="server" />
                <input type="Button" id="mybutton" runat="server" value="Submit" />            
                </td></tr>
            </ItemTemplate>
            <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
        </div>
        </form>
    </body>
    </html>
    And here is the code for Default.aspx.cs. You can simply substitute the code again.

    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection con = new SqlConnection("Your connection string here");
                string sql = "select field1 from table1";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds, "MyTable");
                Repeater1.DataSource = ds;
                Repeater1.DataBind();
            }
            Label1.Text = "";
        }
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HtmlInputCheckBox mychk = (HtmlInputCheckBox)e.Item.FindControl("mycheckbox");
                HtmlInputButton btn = (HtmlInputButton)e.Item.FindControl("mybutton");
                string strvalue = mychk.Value;
                btn.Attributes.Add("onclick", "return openfunc('" + mychk.ClientID +"');");
            }
        }
    }
    Now in the above code you will have to put your appropriate connection string. The database should have a table called table1 in which there is a field called field1. The value of field1 is what will be associated with the check box. You can use the appropriate connection string, field and table names that suit your purpose. In that case you have to change the field1 to the appropriate field name in the html code (Default.aspx) also.

    Now you have to add a second page called targetpage.aspx. Simply go to the solution explorer and add a new web form called targetpage.aspx. I am giving the html code and the code behind for this page below. Simply substitute it.

    Html Code for targetpage.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="targetpage.aspx.cs" Inherits="targetpage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
        </form>
    </body>
    </html>
    Code for targetpage.aspx.cs

    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class targetpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Request.QueryString["filename"];
        }
    }
    Now if you run this application keeping Default.aspx as the start up page then you will see rows of check boxes and buttons. The check box in each row has a value associated with it which is the value of field1 in each corresponding row of table1 your database. It will be different for you if you have substituted different field and table names. If you check any check box and click on the button a pop up window will open up and it will show targetpage.aspx in it. This window will display a label in which the value of the query string parameter "filename" that you passed will be displayed.

    I think it would be clear now. If your requirement is not what I have outlined let me know.

    Warm Regards,
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

  10. #10
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    You got my requirement right except one bit where the submit button appears only once after the <asp:repeater>.

    The difference I noticed in your code is you have added('"+somevariable+"' at return openfunc....I did that with my urlstring and it seems to recognise the url. But i still have issues with not opening the page at the first click of the button. Also, if none of the checkboxes are checked, i click on the button, it seems to remember the previous checkbox. I'll follow the javascript you suggested.
    Last edited by tarunk; March 13th, 2009 at 05:21 AM. Reason: a

  11. #11
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    I have changed my code to include the javascript, infact i tried with your example.
    Instead of sending the id of the submit button, i am sending id of the check to the javascript.

    Code:
    
        <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:Repeater EnableViewState="true" ID="Repeater1" runat="server" >
            <HeaderTemplate><table width= "100%"></HeaderTemplate>
            <ItemTemplate>
               <tr><td>
                <input  name='<%#DataBinder.Eval(Container.DataItem, "SubFolderName") %>' type="checkbox" id="mycheckbox" value='<%#DataBinder.Eval(Container.DataItem, "Name") %>' runat="server" />
                
                </td>
    <td><%#DataBinder.Eval(Container.DataItem, "FullName") %> </td></tr>
            </ItemTemplate>
            <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
            <asp:button id="mybutton" runat="server" text="submit" onclick="somefunction" />          
              
        </div>
        </form>
    </body>
    
    
    
    <script language="c#" runat="server">
          
            protected void somefunction(object sender, System.EventArgs e)
            {
                for (int i = 0; i < Repeater1.Items.Count; i++)
                {
                    HtmlInputCheckBox mychk = (HtmlInputCheckBox)Repeater1.Items[i].FindControl("mycheckbox");
                    
                    mybutton.Attributes.Add("onclick", "return openfunc('" + mychk.ID + "');");
                }
            }
        
        
        
        </script>
    
    
    <script language="javascript" type="text/javascript">
        function openfunc(id)
        {
          var chk = document.getElementById(id);
          if(chk.checked)
          {
             var url = "targetpage.aspx?filename=" + chk.value;
             window.open(url, 'target', 'Height=400,width=400');
          }
          return false;   
        }
        </script>
    What am i doing wrong here? This code does nothing when i click on the submit button. And i don't get any errors, just stays quiet.

  12. #12
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Smile Re: <asp:checkbox> vs <input type="checkbox">

    Hey Tarun,

    That makes life even simpler. I give below a sample program again. Once again open up a new default web site in VS 2005. It will have a web page in it called Default.aspx. I give below the code for Default.aspx and Default.aspx.cs. Simply substitute it.

    Code for Default.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Repeater EnableViewState="true" ID="Repeater1" runat="server">
            <HeaderTemplate><table width= "100%"></HeaderTemplate>
            <ItemTemplate>
               <tr><td>
                <input type="checkbox" id="mycheckbox" value='<%#DataBinder.Eval(Container.DataItem, "field1") %>' runat="server" />
                </td></tr>
            </ItemTemplate>
            <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>
            <asp:Button ID="mybutton" runat="server" value="Submit" onclick="mybutton_Click" />            
        </div>
        </form>
    </body>
    </html>
    And here is the code for Default.aspx.cs

    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection con = new SqlConnection("Your connection string here");
                string sql = "select field1 from table1";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds, "MyTable");
                Repeater1.DataSource = ds;
                Repeater1.DataBind();
    
            }
        }
        protected void mybutton_Click(object sender, EventArgs e)
        {
            string msg = "";
            var filename = "filename";
            for (int i = 0, j = 0; i < Repeater1.Controls.Count; i++)
            {
                try
                {
                    HtmlInputCheckBox chk = (HtmlInputCheckBox)Repeater1.Controls[i].FindControl("mycheckbox");
                    if (chk.Checked)
                    {
                        msg += filename + j.ToString() + "=" + chk.Value + "&";
                        j++;
                    }
                }
                catch
                {
                }
    
            }
            if (msg != "")
            {
                int pos = msg.LastIndexOf('&');
                msg = msg.Substring(0, msg.Length - 1);
                string url = "targetpage.aspx?" + msg;
                string openpopup = "<script language=\"javascript\">window.open('" + url + "', 'target', 'Height=400,width=400');</script>";
                Response.Write(openpopup);
            }
        }
    }
    After substituting the code for Default.aspx and Default.aspx.cs go to solution explorer and add a new page called targetpage.aspx. And here is the code for targetpage.aspx and targetpage.aspx.cs. You can once again substitute it.

    Code for targetpage.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="targetpage.aspx.cs" Inherits="targetpage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
        </form>
    </body>
    </html>
    And here is the code for targetpage.aspx.cs

    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class targetpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Request.QueryString["filename0"] + " " +  Request.QueryString["filename1"];
        }
    }
    I have used the database table name of table1 and field name of field1. One thing you will have to do is to again put in your appropriate connection string and field and table names in Default.aspx and Default.aspx.cs. After doing that you set Defaut.aspx as the start up page and run the application. You will see a row of check boxes and a button at the bottom.

    Now if you check any one check boxes and click on the button, targetpage.aspx will open up in a pop up window and it will show the value associated with the check box you had checked. If you check two check boxes and click on the button the pop up window will list the values associated with the 2 check boxes that were checked. But I haven't coded for listing more than values of 2 checked check boxes in targetpage. But you can always do that.

    You see what is happening is, say there are 10 check boxes displayed in 10 rows in the repeater and you check any 5 of them and click on the button. Then the values associated with the 5 checked check boxes are being passed to targetpage.aspx as query string parameters filename0, filename1, filename2, filename3 and filename4.

    The number of parameters passed depends on the number of check boxes that you have checked before clicking on the button. I have only unraveled a up to 2 values in targetpage. You can always handle that end of it.

    Hope this helps.

    Warm Regards.
    Jay

    ps - Tarun, on second thoughts I thought I might as well attach the sample application. Find attached to this post a file called WebSite3.zip. You can simply unzip it and you will get a directory WebSite3. This is the sample web application I developed. It is developed in Visual web developer 2008. But I am sure it will open in VS 2005 also because there is absolutely no code change. You can use this for your purposes after putting in the appropriate connection string, field names and table names in Default.aspx and Default.aspx.cs. If it does not open in VS 2005 then you may have to cut and paste the code snippets I have given above in a VS 2005 web site.
    Attached Files Attached Files
    Last edited by sr_jay; March 14th, 2009 at 11:00 PM. Reason: I created an attachment
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

  13. #13
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    The latest code seems to do the trick. Response.Write is the way to go rather than btn.attribute.add(onclick.....). is there any reason why it works only at the second click?
    I appreciate your time for writing the code.

    I have similar issue, where after opening the popup page, the user gets to rename the filename and on the close of the popup window, the parent window needs to refresh.

    so i tried onclick of a button
    Code:
    onbtnclick.attributes.add("onclick", "window.close(); window.opener.document.location.href=window.opener.document.location.href;");
    This seems to work but only at the second click of the button. Is it a bug? or something the way i do is not right?

    Like the previous issue, i decided to use Response.write in the onclick event function.....
    Code:
     Response.write(""<script language=\"javascript\">window.close(); window.opener.document.location.href=window.opener.document.location.href;</script>");
    but the popup window just goes blank and does nothing. Obviously i am saying to close it and reload it at the same time.
    Do you have any suggestion for this situation.

    Thank you!

  14. #14
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Smile Re: <asp:checkbox> vs <input type="checkbox">

    Hi Tarun,

    That again is extremely simple. I have attached a sample application again. You can easily download it. The attached application is WebSite80.zip and if you unzip it you will fine a folder called WebSite80. This is the new application. In the target page I have added a button. I will just give the code for the target page here as that is the only thing that changes. The Default page remains the same.

    Code for targetpage.sapx

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="targetpage.aspx.cs" Inherits="targetpage" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>        
        </form>
    </body>
    </html>
    code for targetpage.aspx.cs

    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class targetpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Request.QueryString["filename0"] + " " + Request.QueryString["filename1"];
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            // Put the code for whatever update operations you want to do here 
            
            Response.Write("<script language='javascript'>window.opener.location=window.opener.location;window.close()</script>");
        }
    }
    Hope this helps.

    Warm Regards,
    Attached Files Attached Files
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

  15. #15
    Join Date
    Mar 2007
    Posts
    238

    Re: <asp:checkbox> vs <input type="checkbox">

    Thanks Sr_jay. I'll try the example. I appreciate your help.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center