|
Rank: Advanced Member Groups: Member
Joined: 12/5/2007 Posts: 57
|
What I need to do is as follows. I am displaying the dialog control on one of my web user controls by setting it's InitialState to visible. I have also set the AcceptButton and CancelButton properties to the correct ID's for my buttons in the content template. I have also set the AcceptButtonPostBack and CancelButtonPostBack properties to true.
The first problem I am having is that when I click the Accept button, the page posts and the dialog disappears as expected. However, when I click on the Cancel button the page posts but the dialog control still appears.
My second problem is that I cannot figure out how to trap these click events as I need to perform server side code accordingly.
Lastly, I need to add a textbox to the content area and I need to be able to read it's text value on the server from however I am going to trap the click events.
Anyone out there got asn idea on how I can do this?
Thanks
Gary
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, There should not be any difference between AcceptButton and CancelButton as to InitialState. Neither changes InitialState. So the dialog supposes to be the same state as before. You can test this by putting a simple dialog in the page, then set its InitialState to Visible at design time, then run the page and click the button, you will see the page posts back and the dialog stays visible --- because InitialState is always set to visible. The same goes when you set InitialState by code. It should take whatever value you set there and keeps it. So you might want to check the code that you set IntialState. As for the handling AcceptButton and CancelButton click event, you can do the following:
Code: HTML/ASPX
<ContentTemplate>
<asp:Button id="Button1"
onclick="Button1_Click"
runat="server" Text="Button"></asp:Button>
<asp:Button id="Button2" runat="server" Text="Button"></asp:Button>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
Then add this into your C# code:
Code: C#
protected void Button1_Click(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)Dialog1.ContentContainer.FindControl("TextBox1");
tb.Text = "Hello!";
}
Or this into your VB code:
Code: Visual Basic.NET
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim tb As System.Web.UI.WebControls.TextBox = _
CType(Dialog1.ContentContainer.FindControl("TextBox1"), System.Web.UI.WebControls.TextBox)
tb.Text = "Hello"
End Sub
The above code also demonstrates how to access a textbox inside the dialog. Hope that helps. Please let us know if you still have any more questions. Thanks!
|
|
Rank: Member Groups: Member
Joined: 6/2/2008 Posts: 14
|
I have an issue the same as above but I'm using a dropdownlist and I'm trying to get the value of the selection. When I do an 'update' and try to get the value of the new dropdownlist selection in the Dialog, it reverts back to what was initially selected. I think I know what the problem is, is that the options are pre-populated when the Dialog gets rendered in the page.
My question is, how can I get the new selection and get around this issue? Sorry for not opening a new post. I just thought that since this issue already existed, I might just add on it since it is essentially the same with a little twist.
Thanks guys.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
For this kind of scenario the key is to populate the dropdown list only once when the page initially loads. Specifically, you should re-populate the dropdown list when the page posts back. The drop down list should automatically load the list from view state when it is posted back.
If this does not seem to be a problem, please create a test page that reproduces the problem and we will be happy to take a look.
Thanks
|
|
Rank: Member Groups: Member
Joined: 6/2/2008 Posts: 14
|
I tried putting the dropdownlist and populate values in the if not ispostback clause and it's not populating the values when I do that.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Please create a test page that reproduces the problem and we will be happy to take a look. Make sure the page runs independently.
Thanks
|
|
Rank: Member Groups: Member
Joined: 6/2/2008 Posts: 14
|
I created a simple test page and it works and I looked at my code and it's essentially almost the same. The only biggest difference is my application uses a master page. Does this matter at all?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
You got one page working and one does not. I would definitely think the difference matters.
|
|
Rank: Member Groups: Member
Joined: 6/2/2008 Posts: 14
|
I guess the MasterPage wasn't the issue. Maybe I should have stated this to begin with but I added the Dialog on a column of a GridView and that seems to be what's causing the issue. I'm not sure why, but I just decided at this point to add the Dialog outside and it works just fine.
|
|