1: protected void Page_Load(object sender, EventArgs e)
2: {
3: if (!IsPostBack)
4: {
5:
6: }
7: else
8: {
9: string postBackControlName = GetPostBackControlName(this.Page);
10: if (postBackControlName == "btnSave" || postBackControlName == "DropdDownList1")
11: {
12: ModalPopupExtender1.Show();
13: }
14: }
15: }
16:
17: protected void btnSave_Click(object sender, EventArgs e)
18: {
19: if (Page.IsValid)
20: {
21: lblMessage.Visible = true;
22: }
23: }
24: protected void DropdDownList1_SelectedIndexChanged(object sender, EventArgs e)
25: {
26:
27: }
28:
29: public static string GetPostBackControlName(Page page)
30: {
31: string strControlName = "";
32: Control control = null;
33: //first we will check the "__EVENTTARGET" because if post back made by the controls
34: //which used "_doPostBack" function also available in Request.Form collection.
35: string ctrlname = page.Request.Params["__EVENTTARGET"]; if (ctrlname != null && ctrlname != String.Empty)
36: {
37: control = page.FindControl(ctrlname);
38: }
39: // if __EVENTTARGET is null, the control is a button type and we need to
40: // iterate over the form collection to find it
41: else
42: {
43: string ctrlStr = String.Empty;
44:
45: Control c = null;
46: foreach (string ctl in page.Request.Form)
47: {
48: //handle ImageButton they having an additional "quasi-property" in their Id which identifies
49: //mouse x and y coordinates
50: if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
51: {
52: ctrlStr = ctl.Substring(0, ctl.Length - 2);
53: c = page.FindControl(ctrlStr);
54: }
55: else
56: {
57: c = page.FindControl(ctl);
58: }
59: if (c is System.Web.UI.WebControls.Button)
60: {
61: control = c;
62: break;
63: }
64: }
65: }
66: if (control != null)
67: strControlName = control.ID;
68:
69: return strControlName;
70:
71: }