Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » asp.net c# user control problem
Closed Thread
Old 07-25-2005, 01:19 PM   #1 (permalink)
 
Ultra Techie

Join Date: Feb 2004

Posts: 833

hygor

Default asp.net c# user control problem

I am working on a page which has a form on it with some fields, a save and a cancel button.

There is also a user control (.ascx) which has a text field and an "Add comment" button..

The thing is I have now been asked to add some new features, one of which is to get the save button (on the main page) to add comments as well as save. (currently the add comments button must be clicked and then the save button (as save ignores the comments)).

I have set it so that the main page can see the add comments method on the user control, but it gives an unhandled overload '0' error.

here are some snippets of code:

----------------------------------------------------------
from ascx file: comments.ascx

<script runat="server"> //there is more in here but it is not relevant

public void AddComment(Object s, EventArgs e) {
if (Page.IsValid) {
string textExists = txtComment.Text;
if (textExists !="") {
IssueComment comment = new IssueComment(IssueId, txtComment.Text.Trim(), Page.User.Identity.Name);
comment.Save();
txtComment.Text = String.Empty;
BindComments();
}
}
}

</script>
<asp:TextBox id="txtComment" TextMode="MultiLine" Columns="75" Rows="5" runat="Server" />


<asp:Button id="btnAdd" Text="Add Comment" OnClick="AddComment" CssClass="standardText" Runat="Server" />



---------------------------------------------
from aspx file: Save.aspx

<%@ Register TagPrefix="it" TagName="Comments" Src="~/issues/UserControls/Comments.ascx" %>
<script runat="server">//again some code is left out as not neccessary

void btnSaveClick(Object s, EventArgs e) {
if (Page.IsValid){
ctlComment.AddComment();
SaveIssue();
}
}

</script>
<form runat="server" enctype="multipart/form-data">

<asp:button id="btnSave" runat="server" width="53px" CssClass="standardText" Text="Save" OnClick="btnSaveClick"></asp:button>

<asp:TextBox id="txtTitle" Columns="50" Runat="Server" />
<asp:RequiredFieldValidator ControlToValidate="txtTitle" Text="(required)" runat="Server" />


<it:Comments id="ctlComment" Visible="false" runat="Server" />

</form>



If anyone can help me out that would be great as this needs to be sorted out fairly urgently.

Many Thanks

Hygor
__________________
hygor is offline  
Old 08-04-2005, 10:51 AM   #2 (permalink)
 
Junior Techie

Join Date: Dec 2004

Posts: 88

developer

Default

I think you what u really want to do is access the user controls elements.

I would suggest that you set the text box contents as a public property and then you can recieve the comments written by the user from this property (a public string ought to do the task too).

But in this case you would need to write the Add comments function in the save page.

Another approach would be to reference the function through the class name. Making it a static member would allow you to retain the logic and also allow easy access.
__________________
Somewhere I Belong...
developer is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On