473,288 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

How to send parameter to user control postback

I have a user control being used instead of a frame page. when the user
clicks on a menu item I need to send the ID (integer value) of that menu as
a parameter in the postback of the user control which will be used to query
sql server to repopulate the datagrid in the user control.

I also wrapped the user control in a panel element so I could position it on
the page.

I'm clueless on how to get started with this.

1) how do cause the user control to postback?
2) how do I send a parameter in that postback?

Thanks.

--
mo*******@nospam.com
Nov 18 '05 #1
7 7679
<<I'm clueless on how to get started with this.>>

I'd like to recommend the ASP.NET Commerce starter kit for you (just follow
this link).
http://www.asp.net/Default.aspx?tabindex=9&tabid=47

The starter kits are complete small applications written in ASP.NET (with
either VB or C#, code inline or code behind - you chose which you want to
evaluate). The documentation is excellent - explaining and demonstrating
most basic ASP.NET development tasks and typical application features. You
can install the starter kits on your computer, run the final application,
and dive into the code.

HTH

"moondaddy" <mo*******@nospam.com> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...
I have a user control being used instead of a frame page. when the user
clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control which will be used to query sql server to repopulate the datagrid in the user control.

I also wrapped the user control in a panel element so I could position it on the page.

I'm clueless on how to get started with this.

1) how do cause the user control to postback?
2) how do I send a parameter in that postback?

Thanks.

--
mo*******@nospam.com

Nov 18 '05 #2
Hi moondaddy,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you're using a UserControl in an ASP.NET page. You'd
like to add some control for firing some post back events. Also, you want
to transmit some paramters together with the postback event?
If there is anything I misunderstood, please feel free to let me know.

1. As for the first question, since you're generating a menu via the
UserControl, you can use some "LinkButton" control to act as the hyperlink
of the menus, then because the "LinkButton" has its own postback event, you
can deal with each link's post back event separately, needn't send any
other parameter, how do you think of this?
For example, here is a sample UserControl to show this:
-----------------ascx file--------------------

<table width="500" align="center">
<tr>
<td style="HEIGHT: 20px"><FONT face="ËÎÌå">
<asp:LinkButton id="lnk1" runat="server">Menu1</asp:LinkButton></FONT>
</td>
<td style="HEIGHT: 20px">
<asp:LinkButton id="lnk2" runat="server">Menu2</asp:LinkButton>
</td>
</tr>
<tr>
<td><FONT face="ËÎÌå">
<asp:LinkButton id="lnk3"
runat="server">Menu3</asp:LinkButton></FONT></td>
<td><FONT face="ËÎÌå">
<asp:LinkButton id="lnk4"
runat="server">Menu4</asp:LinkButton></FONT></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
<td></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"></FONT>&nbsp;<FONT face="ËÎÌå">
<asp:Label id="lblUC" runat="server"></asp:Label></FONT>
</td>
<td><FONT face="ËÎÌå">&nbsp; </FONT>
</td>
</tr>
</table>
------------------------------control code behind -------------------------
public class GenericUC : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label lblUC;
protected System.Web.UI.WebControls.LinkButton lnk1;
protected System.Web.UI.WebControls.LinkButton lnk2;
protected System.Web.UI.WebControls.LinkButton lnk3;
protected System.Web.UI.WebControls.LinkButton lnk4;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lnk1.Click += new System.EventHandler(this.lnk1_Click);
this.lnk2.Click += new System.EventHandler(this.lnk2_Click);
this.lnk3.Click += new System.EventHandler(this.lnk3_Click);
this.lnk4.Click += new System.EventHandler(this.lnk4_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnUC_Click(object sender, System.EventArgs e)
{

}

private void lnk1_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu1 is clicked!";
}

private void lnk2_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu2 is clicked!";
}

private void lnk3_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu3 is clicked!";
}

private void lnk4_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu4 is clicked!";
}
}

2. Also, if you don't want to use the LinkButton control, or you prefer to
use some general hyperlink such as
"<a href="........">" and you want to post a event to server when the link
is clicked and also send some parameters. I think you can try use a hidden
field control to store the paramter, for example,
the <input type="hidden" runat= server> control is a good one.

When the link is clicked, first set the proper value of the "hidden"
control and then you can manually fire a button's
click() event to call a post back event to server. You can set the Button's
visible as false so as not to display it on the page. To make my
desciprtion clearly, I've also build a simple test control to show ths
method, here is the source:

-------------------------ascx source-------------------------
<table width="500" align="center">
<tr>
<td>
<a href="#" id="menu1" runat="server">Menu1</a>
</td>
<td>
<a href="#" id="menu2" runat="server">Menu2</a>
</td>
</tr>
<tr>
<td>
<a href="#" id="menu3" runat="server">Menu3</a>
</td>
<td>
<a href="#" id="menu4" runat="server">Menu4</a>
</td>
</tr>
<tr>
<td>
<asp:Label id="lblUC" runat="server"></asp:Label>
</td>
<td> <input type="button" runat="server" value="Post Back"
style="DISPLAY:none" id="btnPostBack"
name="Button1">
<input type="hidden" id="hdParam" runat="server">
</td>
</tr>
</table>
---------------------------------control code-behind class
source--------------------------
public class GenericUC : System.Web.UI.UserControl
{
protected System.Web.UI.HtmlControls.HtmlInputButton btnPostBack;
protected System.Web.UI.HtmlControls.HtmlAnchor menu1;
protected System.Web.UI.HtmlControls.HtmlAnchor menu2;
protected System.Web.UI.HtmlControls.HtmlAnchor menu3;
protected System.Web.UI.HtmlControls.HtmlAnchor menu4;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdParam;
protected System.Web.UI.WebControls.Label lblUC;

private void Page_Load(object sender, System.EventArgs e)
{
string script = hdParam.ClientID + ".value= ";
string script2 = btnPostBack.ClientID + ".click();";
menu1.Attributes.Add("onclick", script + "1;" + script2);
menu2.Attributes.Add("onclick", script + "2;" + script2);
menu3.Attributes.Add("onclick", script + "3;" + script2);
menu4.Attributes.Add("onclick", script + "4;" + script2);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnPostBack.ServerClick += new
System.EventHandler(this.btnPostBack_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


private void btnPostBack_ServerClick(object sender, System.EventArgs e)
{
lblUC.Text = "Menu" + hdParam.Value + " is clicked!";
}


}
Because the control in UserControl's client id will change when it is set
with in a page. So we need to dynamically generate the javascript code in
the code-hehind code.

Please check out the preceding suggestions. If you have any questions on
them or need any help, please feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Thank you Steven. I think this is getting close to what will help me. I
need to clarify the page setup.

I have a main page which will have the typical header menus, graphics, etc.
across the top. then down the left hand side I will have a menu control
dynamically generated from data from the database, but for now, I'm going to
just hard code the menus on the left had side. each menu will name a
category such as animals, food, or what ever. when I click on the menu it
will send the ID for that category (say 43 for example) to the user control
which will take up most of the body of the page. this user control will
replace what a frame page normally would do. so the link button as you
described will reside in main.aspx and it will have to send the value of 43
to a hidden button in the user control as you described below.

Lastly, is it possible to provide the example in vb.net? I apologize for
not specifying the environment earlier which is vb.net 1.1, winxp pro, and
sql server 2k.

Thanks for the great replies.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:wt**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you're using a UserControl in an ASP.NET page. You'd like to add some control for firing some post back events. Also, you want
to transmit some paramters together with the postback event?
If there is anything I misunderstood, please feel free to let me know.

1. As for the first question, since you're generating a menu via the
UserControl, you can use some "LinkButton" control to act as the hyperlink
of the menus, then because the "LinkButton" has its own postback event, you can deal with each link's post back event separately, needn't send any
other parameter, how do you think of this?
For example, here is a sample UserControl to show this:
-----------------ascx file--------------------

<table width="500" align="center">
<tr>
<td style="HEIGHT: 20px"><FONT face="ËÎÌå">
<asp:LinkButton id="lnk1" runat="server">Menu1</asp:LinkButton></FONT>
</td>
<td style="HEIGHT: 20px">
<asp:LinkButton id="lnk2" runat="server">Menu2</asp:LinkButton>
</td>
</tr>
<tr>
<td><FONT face="ËÎÌå">
<asp:LinkButton id="lnk3"
runat="server">Menu3</asp:LinkButton></FONT></td>
<td><FONT face="ËÎÌå">
<asp:LinkButton id="lnk4"
runat="server">Menu4</asp:LinkButton></FONT></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"></FONT></td>
<td></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"></FONT>&nbsp;<FONT face="ËÎÌå">
<asp:Label id="lblUC" runat="server"></asp:Label></FONT>
</td>
<td><FONT face="ËÎÌå">&nbsp; </FONT>
</td>
</tr>
</table>
------------------------------control code behind ------------------------- public class GenericUC : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label lblUC;
protected System.Web.UI.WebControls.LinkButton lnk1;
protected System.Web.UI.WebControls.LinkButton lnk2;
protected System.Web.UI.WebControls.LinkButton lnk3;
protected System.Web.UI.WebControls.LinkButton lnk4;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lnk1.Click += new System.EventHandler(this.lnk1_Click);
this.lnk2.Click += new System.EventHandler(this.lnk2_Click);
this.lnk3.Click += new System.EventHandler(this.lnk3_Click);
this.lnk4.Click += new System.EventHandler(this.lnk4_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnUC_Click(object sender, System.EventArgs e)
{

}

private void lnk1_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu1 is clicked!";
}

private void lnk2_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu2 is clicked!";
}

private void lnk3_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu3 is clicked!";
}

private void lnk4_Click(object sender, System.EventArgs e)
{
lblUC.Text = "Menu4 is clicked!";
}
}

2. Also, if you don't want to use the LinkButton control, or you prefer to
use some general hyperlink such as
"<a href="........">" and you want to post a event to server when the link
is clicked and also send some parameters. I think you can try use a hidden
field control to store the paramter, for example,
the <input type="hidden" runat= server> control is a good one.

When the link is clicked, first set the proper value of the "hidden"
control and then you can manually fire a button's
click() event to call a post back event to server. You can set the Button's visible as false so as not to display it on the page. To make my
desciprtion clearly, I've also build a simple test control to show ths
method, here is the source:

-------------------------ascx source-------------------------
<table width="500" align="center">
<tr>
<td>
<a href="#" id="menu1" runat="server">Menu1</a>
</td>
<td>
<a href="#" id="menu2" runat="server">Menu2</a>
</td>
</tr>
<tr>
<td>
<a href="#" id="menu3" runat="server">Menu3</a>
</td>
<td>
<a href="#" id="menu4" runat="server">Menu4</a>
</td>
</tr>
<tr>
<td>
<asp:Label id="lblUC" runat="server"></asp:Label>
</td>
<td> <input type="button" runat="server" value="Post Back"
style="DISPLAY:none" id="btnPostBack"
name="Button1">
<input type="hidden" id="hdParam" runat="server">
</td>
</tr>
</table>
---------------------------------control code-behind class
source--------------------------
public class GenericUC : System.Web.UI.UserControl
{
protected System.Web.UI.HtmlControls.HtmlInputButton btnPostBack;
protected System.Web.UI.HtmlControls.HtmlAnchor menu1;
protected System.Web.UI.HtmlControls.HtmlAnchor menu2;
protected System.Web.UI.HtmlControls.HtmlAnchor menu3;
protected System.Web.UI.HtmlControls.HtmlAnchor menu4;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdParam;
protected System.Web.UI.WebControls.Label lblUC;

private void Page_Load(object sender, System.EventArgs e)
{
string script = hdParam.ClientID + ".value= ";
string script2 = btnPostBack.ClientID + ".click();";
menu1.Attributes.Add("onclick", script + "1;" + script2);
menu2.Attributes.Add("onclick", script + "2;" + script2);
menu3.Attributes.Add("onclick", script + "3;" + script2);
menu4.Attributes.Add("onclick", script + "4;" + script2);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnPostBack.ServerClick += new
System.EventHandler(this.btnPostBack_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


private void btnPostBack_ServerClick(object sender, System.EventArgs e)
{
lblUC.Text = "Menu" + hdParam.Value + " is clicked!";
}


}
Because the control in UserControl's client id will change when it is set
with in a page. So we need to dynamically generate the javascript code in
the code-hehind code.

Please check out the preceding suggestions. If you have any questions on
them or need any help, please feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hi moondaddy,
Thanks for your response. I've got the detialed requirement from your last
reply. I've rewrote my sample page and the UserControl to perform a more
closely example in account to your situation, here is the new code:

-----------------------------------------------------UserControl's ascx
file-------------------------------------
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="GenericUC.ascx.vb" Inherits="GenericUC"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label></td>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"><INPUT id="hdMenuID" type="hidden" name="hdMenuID"
runat="server"></FONT></td>
<td><FONT face="ËÎÌå"><INPUT id="btnPostBack" style="DISPLAY: none"
type="button" value="PostBack" name="btnPostBack"
runat="server"></FONT></td>
</tr>
</table>

-----------------------UserControl's code behind class----------------------
Public Class GenericUC
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Protected WithEvents hdMenuID As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents btnPostBack As
System.Web.UI.HtmlControls.HtmlInputButton

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnPostBack_ServerClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPostBack.ServerClick
lblMessage.Text = "Menu:" + hdMenuID.Value + " is clicked!"
End Sub
End Class

----------------------------------------------------the sample page's aspx
source-----------------------
<%@ Register TagPrefix="uc1" TagName="GenericUC" Src="GenericUC.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Nav.aspx.vb"
Inherits="Nav"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Nav</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language=javascript>
function PostNotify(hd, value, btn)
{
document.all(hd).value = value;
document.all(btn).click();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><a href="#" id="lnkMenuA" runat="server">MenuA</a></td>
<td><a href="#" id="lnkMenuB" runat="server">MenuB</a></td>
<td><a href="#" id="lnkMenuC" runat="server">MenuC</a></td>
<td><a href="#" id="lnkMenuD" runat="server">MenuD</a></td>
<td><a href="#" id="lnkMenuE" runat="server">MenuE</a></td>
</tr>
<tr>
<td colspan="5">
<uc1:GenericUC id="GenericUC1" runat="server"></uc1:GenericUC></td>
</tr>
</table>
</form>
</body>
</HTML>

------------------------------------sample page's code behind
class---------------------------------
Public Class Nav
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lnkMenuA As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuB As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuC As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuD As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuE As System.Web.UI.HtmlControls.HtmlAnchor

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim uc As GenericUC = Page.FindControl("GenericUC1")
Dim hd As HtmlInputHidden = uc.FindControl("hdMenuID")
Dim btn As HtmlInputButton = uc.FindControl("btnPostBack")

lnkMenuA.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuA','" & btn.ClientID & "')")
lnkMenuB.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuB','" & btn.ClientID & "')")
lnkMenuC.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuC','" & btn.ClientID & "')")
lnkMenuD.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuD','" & btn.ClientID & "')")
lnkMenuE.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuE','" & btn.ClientID & "')")
End Sub

End Class

----------------------------------------------------------------------------

Also, I've attached the page file in this message, please check them out to
see whether they'll work for you. Meanwhile, if you have any other
questions ,please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #5
Big thanks Steven! Your effort in re-writing that is greatly appreciated.
Maybe you can lend some high-level advise. My intent on using the user
control was to replace using a frame page and to force the only the user
control to do a post back and allow it's parent page to not make any
additional roundtrips as there will be a lot of content in it. Am I
approaching this the wrong way? what is the best way to re-load the page in
the user control with the best overall performance? An associate of mine
built a similar page with a complex menu going down the left had side (and
at some point I will have a similar menu) that was used to navigate the
pages in the control which made up the body of the page. every time the
control did a postback, this menu reloaded which I think degraded
performance and visually didn't look good. what are your recommendations
here in regards to emulating the performance gained by a frame page
refreshing only one of its panes as apposed to the entire page?
Thanks.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:M$**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thanks for your response. I've got the detialed requirement from your last
reply. I've rewrote my sample page and the UserControl to perform a more
closely example in account to your situation, here is the new code:

-----------------------------------------------------UserControl's ascx
file-------------------------------------
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="GenericUC.ascx.vb" Inherits="GenericUC"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label></td>
<td><FONT face="ËÎÌå"></FONT></td>
</tr>
<tr>
<td><FONT face="ËÎÌå"><INPUT id="hdMenuID" type="hidden" name="hdMenuID"
runat="server"></FONT></td>
<td><FONT face="ËÎÌå"><INPUT id="btnPostBack" style="DISPLAY: none"
type="button" value="PostBack" name="btnPostBack"
runat="server"></FONT></td>
</tr>
</table>

-----------------------UserControl's code behind class---------------------- Public Class GenericUC
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
Protected WithEvents hdMenuID As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents btnPostBack As
System.Web.UI.HtmlControls.HtmlInputButton

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnPostBack_ServerClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnPostBack.ServerClick
lblMessage.Text = "Menu:" + hdMenuID.Value + " is clicked!"
End Sub
End Class

----------------------------------------------------the sample page's aspx
source-----------------------
<%@ Register TagPrefix="uc1" TagName="GenericUC" Src="GenericUC.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Nav.aspx.vb"
Inherits="Nav"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Nav</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language=javascript>
function PostNotify(hd, value, btn)
{
document.all(hd).value = value;
document.all(btn).click();
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><a href="#" id="lnkMenuA" runat="server">MenuA</a></td>
<td><a href="#" id="lnkMenuB" runat="server">MenuB</a></td>
<td><a href="#" id="lnkMenuC" runat="server">MenuC</a></td>
<td><a href="#" id="lnkMenuD" runat="server">MenuD</a></td>
<td><a href="#" id="lnkMenuE" runat="server">MenuE</a></td>
</tr>
<tr>
<td colspan="5">
<uc1:GenericUC id="GenericUC1" runat="server"></uc1:GenericUC></td>
</tr>
</table>
</form>
</body>
</HTML>

------------------------------------sample page's code behind
class---------------------------------
Public Class Nav
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lnkMenuA As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuB As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuC As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuD As System.Web.UI.HtmlControls.HtmlAnchor
Protected WithEvents lnkMenuE As System.Web.UI.HtmlControls.HtmlAnchor

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim uc As GenericUC = Page.FindControl("GenericUC1")
Dim hd As HtmlInputHidden = uc.FindControl("hdMenuID")
Dim btn As HtmlInputButton = uc.FindControl("btnPostBack")

lnkMenuA.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuA','" & btn.ClientID & "')")
lnkMenuB.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuB','" & btn.ClientID & "')")
lnkMenuC.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuC','" & btn.ClientID & "')")
lnkMenuD.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuD','" & btn.ClientID & "')")
lnkMenuE.Attributes.Add("onclick", "PostNotify('" & hd.ClientID &
"','MenuE','" & btn.ClientID & "')")
End Sub

End Class

-------------------------------------------------------------------------- --
Also, I've attached the page file in this message, please check them out to see whether they'll work for you. Meanwhile, if you have any other
questions ,please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
Hi moondaddy,
Thanks for your response. From your further description in the last reply,
why you used the user control is to let the UserControl be posted back to
server and do dome operations with out post back the mainpage(container
page) ,yes? If so, I'm afraid, you have to use the a <iframe> or frame
structure pages to implement this. Because a UserControl though has its own
html template (ascx file) and codebehind class(ascx.vb), it is still a part
of its container page when be used in a certain main page(container page).
So when the UserControl do post back event, the container page will be
posted back,too. If you'd like the container page not to be posted back
also, I think you still need to use the <iframe> solution. How do you think
of this? Please let me know if my understanding is correct. Also if you
have any other questions please also feel free to post here. I'll be
willing to help you.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7
Hi moondaddy,
Have you viewed my suggestions in the last reply or have you got any ideas
on this issue. If you have any questions or need any help, please feel free
to let me know. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Duwayne | last post by:
I am having lots of trouble with one of my user controls (ascx) not automatically loading postback data. An image on the aspx page starts the postback and the parent has no problem loading it's own...
3
by: Cathie | last post by:
Hi All, I have a few user controls on a page and I need to determine which control caused the PostBack. Is there anyway to do this? Thanks in advance, Cathie
3
by: buran | last post by:
Dear ASP.NET Programmers, I am loading a web user control ("taclient.ascx") into a placeholder (ID: phFA). The web user control contains a cancel button (ID: btnCancel). I would like to "unload"...
6
by: Guadala Harry | last post by:
I have some client-side JavaScript that, among other things, calculates the value of a variable (myVar). On the server I have a stored procedure that needs to somehow receive as an input parameter...
3
by: Guadala Harry | last post by:
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has EnableViewState="true". After a postback, the...
1
by: Robert Howells | last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad architecture. I'd appreciate some feedback on the the wisdom (or lack thereof) in attempting the following: I'm not new...
6
by: Jim | last post by:
I have a user control that I am dynamically loading into an aspx page. When I fill out the text boxes and submit the form using a command button on the aspx page I lose the value from the user...
8
by: Mats Lycken | last post by:
Hi, I'm working on a webproject where I have several different user controls loaded on a WebForm. A problem arises when I in one webcontrol makes a change that should be picked up by another user...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.