issue:not able to get ID of Control in aspx page on .ascx page

hai there, 

im trying to get the ID of the control  which im using  .ASPX page  into  the  .ASCX page 

Is that possible?

assume that having  a grid in aspx page and an usercontrol in .ascx page(one textbox and a submit button) 

here i want to update  the DB and reflect in the grid  once i click the submit button,

since its is a user control click event i have writen  submit_click event in  .ASCX,

 here i was not able to get the grid id to bind the data to it   is that possible,

prakash 

 

 

 

 

0
prakashtelesoft
8/20/2007 10:19:10 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
957 Views

Similar Articles

[PageSpeed] 4

One simple way to achieve this is to expose a public property on your usercontrol which you set in your Page_Load of the aspx page.

Example: 

protected void Page_Load(object sender, EventArgs e)
{
  myComponent.GridView = gridView1;
}

In your usercontrol, you declare a public property like this:

public GridView GridView
{
  set { _gridView = value; }
}
Now you have a member variable _gridView in your usercontrol that you can use to reference the gridview in the page.

If this post was useful to you, please mark it as answer. Thank you!
0
johram
8/20/2007 11:28:53 AM

one thing which you can do is in the prerender event of .aspx page try geeting the value from the usercontrol and bind the grid

0
crewe2007
8/20/2007 11:30:42 AM

Hi parkash,

I understand that you want to access the GridView nested in .aspx page through .ascx page. My suggestion is that you can use Parent.FindControl to find the GridView in aspx page. Please refer to the following code bellow

.ascx page

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UpdateDB.ascx.cs" Inherits="UpdateDB" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
 
public partial class UpdateDB : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string sqlconnect = "Data Source=localhost\\sqlexpress;Initial Catalog=pubs;Integrated Security=True";
        System.Data.SqlClient.SqlConnection sqlconnection = new System.Data.SqlClient.SqlConnection(sqlconnect);

        string command = "update jobs set min_lvl=20 where job_id=@job_id";
        System.Data.SqlClient.SqlCommand sqlcommand = new System.Data.SqlClient.SqlCommand(command);
        sqlcommand.Connection = sqlconnection;


        System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter();
        p.ParameterName = "@job_id";
        p.Value = int.Parse(TextBox1.Text);
        p.SqlDbType = System.Data.SqlDbType.SmallInt;

        sqlcommand.Parameters.Add(p);

        sqlconnection.Open();
        sqlcommand.ExecuteNonQuery();
        sqlconnection.Close();

        GridView gv = (GridView)Parent.FindControl("GridView1");
        gv.DataBind();//rebind the GridView here


    }
}
 

 the .aspx page

    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
            SelectCommand="SELECT * FROM [jobs]"></asp:SqlDataSource>
        <uc1:UpdateDB ID="UpdateDB1" runat="server" />

 Hope it helps,

Jessica


Jessica Cao
Sincerely,
Microsoft Online Community Support


“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
0
Jessica
8/22/2007 9:49:09 AM

 thank you Jessica,this is what i really want,thank you once again,

0
prakashtelesoft
8/23/2007 6:55:06 AM
Reply:

Similar Artilces:

How to get user control id of ASPX page from ascx page..
Hi I have 1 user control which i m using in my aspx page 3 times..... my problem is that i want to get all these thee id of user control (which is in aspx page) from ascx page...whenever any button is clicked within user control....lets have a sample...<uc:RTB ID="RTBText" runat="server" RichTextBoxHeight="130"/><uc:RTB ID="RTBSummary" runat="server" RichTextBoxHeight="130"/><uc:RTB ID="RTBAffilation" runat="server" RichTextBoxHeight="130"/> here 3 user control i have de...

How to get a variable from a web page (.aspx) in a user control (.ascx)
I have a web page with a dropdownlist and a usercontrol.  I would like the usercontrol to be able to read what the selected value is in the dropdownlist.   Any ideas on how this can/should be done are greatly appreciated. I'd suggest that you expose a public property on the Control and have the Page set this when the page does it's postback, for the control to consume. I have a page where I need to get the values from a DropDown prior to postback so I've got a public String and I set the variable whenever ddlYear_SelectedIndexChanged is called.  I also set i...

Controlling ascx page in aspx page
Hi all, Im totally new in asp.net and i have a few questions. I have several page's and on each page i use a header.ascx to display the header on each aspx page. How can i control for example a label (lblCustom.text, lblCustom.visible) wich is placed in my ascx file with code in my aspx page ?? My second question?? I want to email some information to several people in my web application. The problem is the content of the email is not displayed very nice, for example username:.......test password: ...................abcdfdf Address: .....teststreet (the dots are ...

Validating web user control(ascx) in parent page (aspx) -- .NET 1.1
Hi,  I have a user control which has some asp.net server controls like drop down list, list box etc. These fields are required. I'm using this control in a parent page which has its own server controls which are also required. The button on the parent page which is supposed to validate the controls is not working after I add the web user control.  Is there a work-around for this scenario  other than manually calling Page.Validate() and checking for Page.IsValid property ? I tried calling a javascript on button click which calls Page_ClientValidate() whic...

A page can have only one server-side Form tag
I have a web user control in my web page.  The user control (ascx) consist of a text box and button. The web page consist of text boxes and buttons also.  Both pages have form tags with runat=server.  When I run the web page it comes up with the error "A page can have only one server-side Form tag." Both the user control and web page need the form tag with runat=server.  Is there a way I can code these pages where there won't be a conflict between the web user control and the web page? Thanks   JohnMo wrote:Both the user control and web page need the form tag wit...

How to pass textbox control value from UserControl page(ascx) to Page Control(aspx).
I have 2 files(aspx and ascx). the aspx page  has a Web user control(ascx) in it.Once the button control click(in aspx) I want to get the value from the textbox(ascx) controland pass it to label control in aspx page.Can somebody help with this and please use VB.Thanks A simple search would have turn up many different solutions.  The easiest is to just expose the textbox value as a property in your control.  Then you can retrieve that value on the aspx page. Add this to your control: Public Property TextBoxValue() As String   Get   &...

Control Menu in ascx page from aspx page
Hi all, Hope you can help. I have a menu in an ascx page that I want to change the visible status on based on whether a user is authenticated or not. If on the aspx page I try to change the state of the menu, I get the error that the menu is protected. I have very limited programming experience and can't find any info on this All help is welcome   Argy     In the Page_Load() Event, do this: If Page.User.Identity.IsAuthenticated = True Then Menu1.Visible = False Else Menu1.Visible = True End If  Specializing in...

Web page .aspx is slow when loading. Pages have web user controls on them that are loaded dynamically
I have written a web application using VS 2003. Several of my forms have web user controls on them. The controls are loaded dynamically at runtime. The problem is that the web pages are very slow to load. Does anyone know if there is a way to speed up the pages being loaded into the browser? Here is an example of some code I use to dynamically load the controls:  private void Page_Load(object sender, System.EventArgs e)  {   // Put user code to initialize the page here   // Put user code to initialize the page here    Co...

Can my web page with a form submit to other web pages forms?
I was wondering if I created an aspx page that had a form on it that I could use the submit button to submit this form's contents to other web pages forms(servers accepting those form's data). I am thinking this would be a great way to update data on particular web pages without having to actually visit those similar web pages. Any ideas, examples would be much appreciated. Thanks in advance.  Yes you can.  It's called Cross Page Posting: http://msdn2.microsoft.com/en-us/library/ms178139.aspxAlso: http://msdn2.microsoft.com/en-us/library/ms178140.aspx might ...

Get no Master Page checkbox on creating .aspx page in WAP like in Web Site .aspx?
I am trying to convert a web site to a web application project.  However, whenever I create an .aspx page in the project, VS 2005 does not give me an option to include my application Master Page and instead I have to edit the XML text to remove the html and add a Master Page reference with content area.  This get kind of tedious.  Am I missing something?  Is there some sort of configuration setting to provide a Master Page selection in a WAP template?  Or, am I stuck with having to manually edit the content .aspx?Ron K.------------------------------The only differenc...

How to Access Parent Page (.aspx) control (IDs) from its child User Control (.ascx)
I have a parent .aspx page that has a asp:panel control in it, and this parent .aspx is also referencing a user control that I registered in that .aspx. Lets just call it usercontrolA.ascx for this post.The user control has a radiobuttonlist itself.Based on a selection from the radiotbuttonlist in the user control, I want to be able to hide the asp:panel in my .aspx (parent) but unfortunately I cant' get it to work:parentPanel.visible = true;  <<< I trried this in usercontrolA.ascx.csBut the user control doesn't know about the panel in the parent .aspxSo do I need to ex...

getting focused Control from a web page with master page
Hi All, I would like to get some ideas about for the java script as I am new to that area. I'd like to set up a script which will get the control id which is being focused and according to the control id I'd like to set a different message to a text box. If you have any link or ideas of your own, please share with me. The logic is I will have like 6 or 7 controls on the page with a master page.(I am using MS AJAX) When user changes the focus from control to control I would like to display the message in a text box. Like...If the focus is on textbox 1 The message will be &qu...

Do not get expected WEb page on secondary
netware 6.5 sp2 Have setup a web page on a seconary IP address Load appache with the following command line LOAD ADDRESS SPACE = CSMI APACHE2 -f SYS:APACHE2\CSMI\SERVER\HTTPD.CONF Where HTTPD.CONF is set up to Listen 172.16.212.2:80 which is a secondary ip address A display secondary ipaddress at the server lists the seconary ipaddress I can ping the secondary ip address from the client in Remote manager using IP Address management the secondary IP addresses are not listed When I attempt to brose to the HTTP://172.16.212.2 address I do not see the web page I...

Web Menus / User controls in aspx web page and .aspx C# based web templates
Dear all, I have created several user controls and included in the webpages. (This user control is a navigation menu consisting of images) This has to be included in all webpages. But when i tried to publish i get error messages for them. But i can’t remove since i need these user controls. Error message given below Error 2 The type 'WebUserControl' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_latest\d203e69a\d67c356f\App_Web_ijsq-eqk.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_la...

Web resources about - issue:not able to get ID of Control in aspx page on .ascx page - asp.net.web-forms

Resources last updated: 12/5/2015 8:30:35 AM